Swift - WebView 在加载时未检测到滑动
Posted
技术标签:
【中文标题】Swift - WebView 在加载时未检测到滑动【英文标题】:Swift - WebView doesn't detect swipes when loading 【发布时间】:2016-08-02 22:24:43 【问题描述】:在 URL 完成加载之前,在检测到滑动之后,未检测到我的滑动。知道如何在 URL 加载时检测滑动吗?
【问题讨论】:
你能展示你的代码吗? 【参考方案1】:我刚刚发现,我们只需要添加这两行:
webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(rightSwipeGesture)
webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(leftSwipeGesture)
完整示例:
var rightSwipeGesture: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipeGesture))
var leftSwipeGesture: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipeGesture))
rightSwipeGesture.direction = .Right
leftSwipeGesture.direction = .Left
self.view!.addGestureRecognizer(rightSwipeGesture)
self.view!.addGestureRecognizer(leftSwipeGesture)
webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(rightSwipeGesture)
webView.scrollView.panGestureRecognizer.requireGestureRecognizerToFail(leftSwipeGesture)
【讨论】:
以上是关于Swift - WebView 在加载时未检测到滑动的主要内容,如果未能解决你的问题,请参考以下文章
HTML5 - 在 Android WebView 中首次加载时未呈现画布
如何在 Swift 上将 HTML 代码加载到 WebView