Prevent UIWebView for Repositioning for input field(防止 UIWebView 重新定位输入字段)
问题描述
我有一个 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 重新定位输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:防止 UIWebView 重新定位输入字段


基础教程推荐
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01