我正在使用webView
,我希望在用户点击webView
时执行某些操作,因为我使用UITapGestureRecognizer
这样的方式:
import UIKit
class ViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet var webView: UIWebView!
let SingleTap = UITapGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
let url = NSURL(string: "http://rshankar.com")
let request = NSURLRequest(URL: url!)
webView.loadRequest(request)
SingleTap.delegate = self
SingleTap.addTarget(self, action: "SingleTap:")
SingleTap.numberOfTapsRequired = 1
SingleTap.numberOfTouchesRequired = 1
self.webView!.scrollView.addGestureRecognizer(SingleTap)
}
func SingleTap(gestureRecognizer:UIGestureRecognizer){
println("touch detected")
}
}
但这对我不起作用,以后我会这样尝试同样的事情:
let aSelector : Selector = "UserTap:"
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1
self.webView.addGestureRecognizer(tapGesture)
func userTap(tapgesture : UITapGestureRecognizer){
println("user tapped")
}
但它不适合我。
我错过了一些事情,请帮助我。在此先感谢。