防止 UIWebView 重新定位输入字段

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

    本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

    相关文档推荐

    Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
    iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
    tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
    Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
    How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
    How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)