gpt4 book ai didi

ios - Swift 3 webview 触摸事件

转载 作者:搜寻专家 更新时间:2023-11-01 07:17:22 28 4
gpt4 key购买 nike

我试图在我的 swift 3 应用程序中包含一个 webview 触摸事件,但这样做仍然不成功。

我尝试通过谷歌搜索时发现的以下示例来使用 toucheBegan 和 touchesEnd 事件。有人可以通过 swift 3 的代码片段或链接吗

我正在尝试这种方式

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
super.touchesBegan(touches, with: event)
}

但不工作。我不知道如何在其中集成webview。

最佳答案

为所有类型的 View 实现 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
}

对于触摸开始和触摸结束尝试通过重写 native 方法使用该代码。

override func touchesBegan(touches: Set, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let touch: UITouch = touches.first as! UITouch
if (touch.view == yourView){
println("touchesBegan | This is an ImageView")
}else{
println("touchesBegan | This is not an ImageView")
}
}

触摸端功能。

override func touchesEnded(touches: Set, withEvent event: UIEvent) { 
super.touchesMoved(touches, withEvent: event)
let touch: UITouch = touches.first as! UITouch

if (touch.view == yourView){
printing("touchesEnded | This is an ImageView")
}
else{
println("touchesEnded | This is not an ImageView")
}
}

关于ios - Swift 3 webview 触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41408674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com