如何将单点触摸事件传递到UIWebView中的超级视图?

问题描述 投票:0回答:2

我正在使用UIWebView显示pdf。我想处理webview上的触摸事件。有两个条件,我的WebView应该处理两次触摸事件和手势,我想将单击/触摸事件传递给超级视图。

谁能告诉我如何区分UIWebView中的触摸事件以及如何将特定的触摸事件传递到其超级视图?

要获取触摸事件,我将uiwebview子类化,并在子类中覆盖hitTest方法。

iphone cocoa-touch iphone-sdk-3.0 uiwebview
2个回答
1
投票

如果该帖子未回答您的问题,则应签出this article

[我采用了类似但略有不同的方法:我将UIView子类化,该UIView包含UIWebView(和其他控件),并重写hitTest:withEvent:方法。


0
投票

子类Web视图,并在子类中使用hitTest(_ point:CGPoint,带有事件:UIEvent?)方法,如下所示:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    if let hitTestingView = super.hitTest(point, with: event) {
        if shouldHandleTouch // Logic on which this view should handle touch or not. If you don't want to handle always then return nil {
            return hitTestingView
        } else {
            return nil
        }  
    } else {
        return nil
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.