带目标的UITapGestureRecognizer – Swift

我试图做一个简单的点击手势,我无法弄清楚。 我想添加一个目标,简单的select器的手势。

这是我的代码:

var panGesture : UIGestureRecognizer = UITapGestureRecognizer.addTarget(<#UIGestureRecognizer#>) 

我如何设置select器?

应该看起来像这样:

 var tapGesture = UITapGestureRecognizer(target: self, action: "SomeMethod") self.view.addGestureRecognizer(tapGesture) 

Swift 3:

添加点击手势目标:

 sampleTapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.sampleTapGestureTapped(recognizer:))) self.view.addGestureRecognizer(sampleTapGesture!) 

相关function:

 func sampleTapGestureTapped(recognizer: UITapGestureRecognizer) { print("Tapping working") }