WKWebView Mac OS禁用用户交互

时间:2018-10-31 21:22:25

标签: swift xcode wkwebview

如何确定对WKWebView加载的内容禁用所有用户交互的要求? 我没有找到合适的方法或属性,所以我想到了将其他任何透明视图置于Web视图上的想法。不幸的是,没有成功。有什么通用的方法可以解决此类问题吗?

2 个答案:

答案 0 :(得分:0)

你累了吗?

self.wkwebView.isUserInteractionEnabled = false

或使用此方法

func removeTapGestures() {
    for subView in self.scrollView.subviews {
        if let recogniserz = subView.gestureRecognizers {
            for recogniser in recogniserz {
                if recogniser is UITapGestureRecognizer {
                    subView.removeGestureRecognizer(recogniser)
                }
            }
        }
    }
}

答案 1 :(得分:0)

这对我有用...

public class WebViewWhichIgnoresTheMouse: WKWebView
{
    override public func scrollWheel(with event: NSEvent)
    {
        self.nextResponder?.scrollWheel(with: event)
    }
    
    override public func mouseDown(with event: NSEvent)
    {
        self.nextResponder?.mouseDown(with: event)
    }
    
    override public func mouseUp(with event: NSEvent)
    {
        self.nextResponder?.mouseUp(with: event)
    }
}