我有一个 iPad 应用程序,我在其中将输入表单显示为 UIPopoverController 中的 UIWebView.我的弹出框控制器的大小使得当键盘出现时不必调整它的大小.
I have an iPad application in which I am displaying an input form as a UIWebView in a UIPopoverController. My popover controller is sized such that it does not have to be resized when the keyboard appears.
当我点击 UIWebView 中的输入字段时,当键盘出现时,Web 视图会被进一步向上推.它被推到文本字段位于框架顶部的位置.(这是您在移动 Safari 中使用表单时看到的标准行为).
When I tap in an input field in the UIWebView, the web view is pushed further up when the keyboard appears. It is pushed up to the point that the text field is at the top of the frame. (This is the standard behavior you see when using forms in mobile safari).
在键盘启动之前,webview 根本不滚动,但一旦滚动,(如第二张图片所示)我可以将 webview 向下滚动到正确的位置.
The webview does not scroll at all before the keyboard is up, but once it is, (as seen in the second image) I can scroll the webview back down to the correct position.
因为我的 webview 的大小已经正确,所以我不想要这种行为.有人对如何防止这种情况有任何建议吗?(目前不可以在这里不使用网络视图)
Because my webview is already sized correctly, I do not want this behavior. Does anyone have any suggestions on how to prevent this? (Not using a web view here is currently not an option)
谢谢!
在viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
实现keyboardWillShow: 并重新调整WebviewScroller 方法
Implement keyboardWillShow: and readjustWebviewScroller methods
- (void)keyboardWillShow:(NSNotification *)aNotification {
[self performSelector:@selector(readjustWebviewScroller) withObject:nil afterDelay:0];
}
- (void)readjustWebviewScroller {
_webView.scrollView.bounds = _webView.bounds;
}
这对我有用.
这篇关于防止 UIWebView 重新定位输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!