ios 带有目标的 UITapGestureRecognizer - Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24085922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 00:36:25 来源:igfitidea点击:
UITapGestureRecognizer with target - Swift
提问by Ron
I tried to make a simple tap gesture and I can't figure it out. I want to add a target, simple selector to the gesture.
我试图做一个简单的点击手势,但我无法弄清楚。我想为手势添加一个目标、简单的选择器。
Here is my code :
这是我的代码:
var panGesture : UIGestureRecognizer = UITapGestureRecognizer.addTarget(<#UIGestureRecognizer#>)
How can I set selector?
如何设置选择器?
回答by Kris Gellci
Should look something like this:
应该是这样的:
var tapGesture = UITapGestureRecognizer(target: self, action: "SomeMethod")
self.view.addGestureRecognizer(tapGesture)
回答by A.G
Swift 3:
斯威夫特 3:
Adding Tap Gesture Target:
添加点击手势目标:
sampleTapGesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.sampleTapGestureTapped(recognizer:)))
self.view.addGestureRecognizer(sampleTapGesture!)
Associated Function:
相关功能:
func sampleTapGestureTapped(recognizer: UITapGestureRecognizer) {
print("Tapping working")
}