UIWebView 在键盘出现时滚动.导致点击偏移错误
UIWebView scrolling when keyboard appears. Causing tap offset bug?
我有一个UIWebView
,其中包含需要用户输入iPad应用程序的登录字段。视图以模式显示,当横向显示时,键盘显示,这会导致UIWebView
向上滚动。
这是错误发生的地方 - UIWebView
包含一个点击延迟,我还没有找到可靠的解决方案。(我正在使用OAuth
所以任何Javascript
注入都无法可靠地工作)。显示键盘,因此当我点击输入字段时,点击会在视图自动滚动并且不在正确的位置后注册。
从本质上讲,这就是我点击顶部输入字段,并且点击记录的比应有的低约 20px,因为视图正在被键盘移动。
我尝试过防止UIWebView
滚动,但无论如何键盘总是让它移动。我尝试注入Javascript
以消除点击延迟,但也没有成功。
任何帮助不胜感激!
我正在努力解决同样的问题。我还没有解决抽头偏移问题,但就关闭抽头延迟而言,您可以使用:
[[self.webView scrollView] setDelaysContentTouches:NO];
不确定您是否已经找到此页面,但您可以为键盘通知添加侦听器并自己操作滚动。这是苹果的文档链接:https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
以下是链接中与操作视图相关的代码:
// Call this method somewhere in your view controller setup code.
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
[self.scrollView scrollRectToVisible:activeField.frame animated:YES];
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
似乎uiwebview中的某些点击区域并不总是随着键盘而移动。解决这个问题的一个肮脏的技巧是在按钮/等上放置一个不可见的文本div,并带有一些空格,并让它调用一个javascript函数,该函数试图完成任何未注册的触摸事件。这样:
<div id="someBtn" onclick="tryAction();"> </div>
我希望这能有所帮助,或者至少为您指明一个有用的方向。
- 将菜单项与滚动绑定时出现Jquery错误
- 为什么'滚动到顶部'脚本导致类型错误?jQuery冲突
- 引导表单向导 - 防止在提交 ajax 响应的每个页面表单出现错误时滚动到下一步
- 在 JavaScript 中向下滚动部分的错误
- 正在尝试滚动页面:未捕获类型错误:无法读取属性'top'的未定义
- 滚动字幕未捕获类型错误:无法读取属性'style'的未定义
- 滚动粘贴指令错误
- 滚动功能工作方向错误
- 点击jQuery按钮出现页面滚动错误
- 带有转换比例错误的自定义JavaScript滚动条(jScrollPane)
- 类型错误:使用 requireJs 时未定义滚动到
- UIWebView 在键盘出现时滚动.导致点击偏移错误
- jQueryUI 滚动到顶部错误
- 更改 :后内容时的火狐滚动错误
- j轮播自动滚动不起作用,没有错误
- 滚动过程中的错误行为,根据代码的链接方式显示
- 火狐中的滚动错误
- 滚动侧边栏抛出 Javascript 错误“无法调用 null 的方法'偏移量'
- 错误“JavaScript 运行时错误:查找滚动位置时无法获取未定义或空引用的属性'scrollLeft'”
- DIV 向下滚动到底部 脚本错误 JQUERY