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 重新定位输入字段
基础教程推荐
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
