【问题标题】:How to completely disable magnifying glass for UIWebView iOS9如何完全禁用 UIWebView iOS9 的放大镜
【发布时间】:2015-12-17 16:33:05
【问题描述】:

我尝试了以下方法:

html, body, div, p, a, table, img
{
-webkit-user-select: none !important;
user-select: none !important;
-webkit-user-callout: none !important;
-webkit-touch-callout: none !important;
}

这适用于我的占据整个屏幕的 uiwebview,但对于我的 uiwebview(上面的 adbannerview),它会将 uiwebview 上方的放大镜推到 adbannerview 上方。

有没有人有任何想法不涉及在这个answer 中建议的 uiwebview 的子视图上禁用 UILongPressGestureRecognizers

【问题讨论】:

  • @rmaddy,请阅读我的问题。它不是那个问题的重复。我尝试了他们的解决方案,甚至将他们的解决方案放在我的问题中并解释了它的作用。
  • 同样的问题,请问有什么解决办法吗?
  • @HassanTaleb 除了我在我的问题中发布的答案。只要您不介意在所有 uiwebview 子视图上禁用 UILongPressGestureRecognizers,那么您就有了一个非常好的解决方案。回答者担心苹果拒绝,这一直是一个问题。我认为这对他们来说不是问题。但你永远不知道。
  • 我不理解“uiwebview subviews”,我试图禁用 uiwebview 中的 UILongPressGestureRecognizers,如下所示:let LongTapWebVIew = UILongPressGestureRecognizer() 然后:func LongTapWebViewGesture(){ LongTapWebVIew.addTarget(self, action: "tappedLongWebView") LongTapWebVIew.delegate = self WebView.addGestureRecognizer(LongTapWebVIew) } 然后func tappedLongWebView() { LongTapWebVIew.enabled = false } 然后在 viewDidLoad 中调用 LongTapWebViewGesture() ,但是放大镜仍然显示:/..你能给我一些提示或代码吗? @mark

标签: ios css objective-c uiwebview ios9


【解决方案1】:

我通过从 webview 迭代子视图并找到具有 UILongPressGestureRegonizer 然后禁用它来禁用放大镜

这里是sn-p:

- (void)disableWebViewLongPressGestures:(UIWebView *)webview {
    for(id subView in webview.subviews) {
        if([subView isKindOfClass:[UIScrollView class]]) {
            UIScrollView *scrollView = (UIScrollView *)subView;
            for(id ssView in scrollView.subviews) {
                if([NSStringFromClass([ssView class]) isEqualToString:@"UIWebBrowserView"]) {
                    for(UIGestureRecognizer *gs in [ssView gestureRecognizers]) {
                        if ([gs isKindOfClass:[UILongPressGestureRecognizer class]])
                        {
                            gs.enabled = NO;
                        }
                    }
                }
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    通过确保在每次页面加载后禁用手势,我设法让建议的 cmets 正常工作。

    所以,在你的 webview 委托中:

    func webViewDidFinishLoad(webView: UIWebView) {
        disableLongPressGesturesForView(webView)
    }
    

    然后您的函数可以查找 webview 的每个子视图(以及它的子视图子视图),并禁用任何长按手势。

    func disableLongPressGesturesForView(view: UIView) {
        for subview in view.subviews {
            if let gestures = subview.gestureRecognizers as [UIGestureRecognizer]! {
                for gesture in gestures {
                    if gesture is UILongPressGestureRecognizer {
                        gesture.enabled = false
                    }
                }
            }
            disableLongPressGesturesForView(subview)
        }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2021-11-28
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多