gpt4 book ai didi

ios - 为 UIWebView 拦截 UITapGestureRecognizer

转载 作者:搜寻专家 更新时间:2023-11-01 05:47:08 27 4
gpt4 key购买 nike

我想弄清楚如何拦截 UIWebView 上的点击事件。似乎正确的手势是 UITapGestureRecognizer,但我似乎无法获得正确的 View 。我一直无法快速找到解决方案。我的层次结构是 View -> UIWebView。我的用例是部署一个网络应用程序,并有一些基于 WebView 导航的自定义操作。例如,能够识别我想要转换插页式广告或显示 UINavigationBar 的导航事件。感谢您的帮助!

import UIKit

class ViewController: UIViewController {

@IBOutlet var Webview: UIWebView!

let URLPath = "http://www.example.com"

func loadAddressURL(){

let requestURL = NSURL(string: URLPath)
let request = NSURLRequest(URL: requestURL!)
Webview.loadRequest(request)

}

override func viewDidLoad() {
super.viewDidLoad()

loadAddressURL()
NSLog("I'm getting going")

//NOT SURE IF YOU SHOULD DISABLE THIS OR NOT
//Webview.userInteractionEnabled=false


let tapRecognizer = UITapGestureRecognizer(target: self , action: "handleSingleTap:")
NSLog("I'm past the tab recognizer!\(tapRecognizer)")

tapRecognizer.numberOfTapsRequired = 1
Webview.addGestureRecognizer(tapRecognizer)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func handleSingleTap(recognizer: UITapGestureRecognizer) {
//
NSLog("I made it here")
}

}

最佳答案

先设置GestureDelegate并继承getureUIGestureRecognizerDelegate

tapRecognizer.delegate = self

并插入这个代表

func gestureRecognizer(UIGestureRecognizer,  shouldRecognizeSimultaneouslyWithGestureRecognizer:UIGestureRecognizer) -> Bool 
{
return true
}

试试这个也许很有帮助...

关于ios - 为 UIWebView 拦截 UITapGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31107656/

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