我尝试做一个简单的点击手势,我无法理解。我想为手势添加一个目标,简单的选择器。
这是我的代码:
var panGesture : UIGestureRecognizer = UITapGestureRecognizer.addTarget(<#UIGestureRecognizer#>)
如何设置选择器?
答案 0 :(得分:48)
应该是这样的:
var tapGesture = UITapGestureRecognizer(target: self, action: "SomeMethod")
self.view.addGestureRecognizer(tapGesture)
答案 1 :(得分:9)
Swift 3:
添加Tap Gesture目标:
sampleTapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.sampleTapGestureTapped(recognizer:)))
self.view.addGestureRecognizer(sampleTapGesture!)
相关功能:
func sampleTapGestureTapped(recognizer: UITapGestureRecognizer) {
print("Tapping working")
}