Swift 3 - 检测 UIWebView 中的非事件

标签 swift xcode uiwebview

我希望能够检测 UIWebView 中是否没有用户事件(例如滚动/点击)。我只找到了一个检测点击的代码,但不检测 UIWebView 中的滚动。

override func viewDidLoad() {
    super.viewDidLoad()
    let tapRecognizer = UITapGestureRecognizer(target: view, action: #selector(handleSingleTap))
    tapRecognizer.numberOfTapsRequired = 1
    self.view.addGestureRecognizer(tapRecognizer)
}

@objc func handleSingleTap(recognizer: UITapGestureRecognizer) {
    //Do something here with the gesture
}

最佳答案

只需将 webview 的 scrollview delegate 设置为 self。

webView.scrollView.delegate = self

并符合委托(delegate)方法scrollViewDidEndDeceleratingscrollViewDidEndDraggingscrollViewDidScrollscrollViewWillBeginDragging

在这些方法中,检查内容偏移量的变化,并使用它来计算是否发生滚动。

Find the details in this and this.

关于Swift 3 - 检测 UIWebView 中的非事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48376120/

相关文章:

ios - "Search Paths"中缺少 "Build Settings"

iphone - 使用 webview 在 iphone 应用程序中播放来自 youtube 的视频

ios - 捕获手势识别器开始状态的 Swift 惯用方法

ios - 具有自动布局的 UIPageViewController 在 vi​​ewDidAppear 之前不会更新子框架

ios - UITextField becomeFirstResponder 随机崩溃 iOS 应用程序

iphone - UIWebView完成加载事件

iphone - 有人在 iPhone 应用程序中成功使用 CFAllocatorSet Default 吗?

swift - 为 Apple Watch 并发症设置 tintColor

swift - 遵守协议(protocol)(作为协议(protocol))

Xcode Developer Tools 文件夹很大