阻止UIWebView重新定位输入字段 [英] Prevent UIWebView for Repositioning for input field

查看:97
本文介绍了阻止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)

谢谢!


推荐答案


  1. 添加 UIKeyboardWillShowNotification NSNotificationCenter in viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(keyboardWillShow:) 
    name:UIKeyboardWillShowNotification object:nil];


  • 实施keyboardWillShow:和readjustWebviewScroller方法

  • 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重新定位输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆