I have a UIWebView with login fields that require user input for an iPad app. The view is presented modally and when landscape the keyboard is presented which causes the UIWebView to scroll up.

Here's where the bug happens - the UIWebView contains a tap delay which I haven't found a reliable solution around it. (I'm using OAuth so any Javascript injecting hasn't worked reliably). The keyboard is presented so when I tap on the input field, the tap is registered after the view is scrolled automatically and is not in the correct spot.

我有一个UIWebView,其登录字段需要用户输入iPad应用程序。视图以模态方式呈现,当呈现横向键盘时,会导致UIWebView向上滚动。这是bug发生的地方 - UIWebView包含一个tap延迟,我没​​有找到可靠的解决方案。 (我正在使用OAuth,因此任何Javascript注入都无法可靠地工作)。键盘出现时,当我点击输入字段时,在视图自动滚动并且不在正确的位置后注册点击。

Essentially, this is making it so I tap on the top input field, and the tap is registered about 20px lower than it should because the view is being shifted by the keyboard.

基本上,这是因为我点击顶部输入字段,并且水龙头的注册量比它应该低约20px,因为视图正被键盘移动。

I've tried preventing the UIWebView from scrolling, but the keyboard always makes it shift no matter what. I've tried injecting Javascript to remove the tap delay, but haven't had success there either.

我试过阻止UIWebView滚动,但键盘总是让它无论如何都会移动。我已经尝试注入Javascript以消除点击延迟,但也没有取得成功。

Any help is appreciated!

任何帮助表示赞赏!

1 个解决方案

#1


2

I'm grappling with this same issue. I have not solved the tap offset issue yet but as far as turning off the tap delay you can do it using:

我正在努力解决同样的问题。我还没有解决水龙头偏移问题,但就关闭水龙头延迟你可以使用:

[[self.webView scrollView] setDelaysContentTouches:NO];

Not sure if you have found this page yet, but you can add listeners for keyboard notifications and manipulate scrolling yourself. Here is Apple's documentation link: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

不确定您是否已找到此页面,但您可以添加键盘通知的监听器并自行操作滚动。这是Apple的文档链接:https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

Here is the code from the link pertaining to manipulating the view:

以下是与操作视图相关的链接中的代码:

// 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;
}

It seems like some hit areas within uiwebview don't always shift up with the keyboard. One dirty hack to get around this is to place an invisible text div over the button/etc with some spaces and have it call a javascript function that tries to accomplish whatever touch event is not registering. Like so:

似乎uiwebview中的一些热门区域并不总是随着键盘向上移动。一个肮脏的黑客来解决这个问题是在按钮/ etc上放置一个不可见的文本div,并使用一些空格调用一个javascript函数来尝试完成任何未注册的触摸事件。像这样:

<div id="someBtn" onclick="tryAction();">&nbsp;&nbsp;&nbsp;&nbsp;</div>

I hope this helps or at least points you in a useful direction.

我希望这有助于或至少指出你有用的方向。

更多相关文章

  1. 有没有办法用JavaScript控制iPod Touch的键盘方向?
  2. 在用户将'n'粘贴复制到文本字段后,如何更新视图模型?
  3. 在项目之间共享ASP.NET MVC部分视图
  4. 如果外部应用程序更改了持久模型(服务器数据库),AngularJS可以自
  5. 如何在rails中使用ajax将数据从控制器传递到视图
  6. django的视图和URL配置
  7. Python Flask WTForms:如何在视图中动态禁用字段?
  8. 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
  9. Django反向url与参数到基于类的视图

随机推荐

  1. Android ListView重要美化属性
  2. Android面试系列文章2018之Android部分We
  3. EditText 的一些属性设置
  4. Android中的Handler的机制与用法详解
  5. Android(安卓)Camera数据流分析全程记录(
  6. 《IT蓝豹》吹雪花demo,学习android传感器
  7. android 编程问题集结1
  8. Android 安全加密:消息摘要Message Digest
  9. android中的UI中的窗口之Window类介绍
  10. android sdk 安装