UIWebView和触摸事件 [英] UIWebView and touch event

查看:107
本文介绍了UIWebView和触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在视图中使用自定义触摸事件。有一个Web视图,它是此视图的子视图。
我覆盖了touchBegan和其他功能,但它没有运行。

I want use a custom touch event in a view. There is a web view which is the subview of this view. I override touchBegan and other functions but it does not run.

推荐答案

如果你想在点击时调用一个函数您可以使用UITapGestureRecognizer的视图

If you want to call a function while tapping a view you can use UITapGestureRecognizer

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

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

对于Swift 3:

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
}

这篇关于UIWebView和触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆