[英]How to pass the UIView with a gesture recognizer as parameter?
I use: 我用:
tap.addTarget(self, action: "handleTap:")
self.view.addGestureRecognizer(tap)
I want to access to the view.tag
property of view
in handleTap
method. 我想在
handleTap
方法中访问view
的view.tag
属性。 So how do I pass the UIView which "tap" is in as parameter of handleTap? 那么,如何通过UIView中的“ tap”作为handleTap的参数呢?
Thanks. 谢谢。
func handleTap(sender:UITapGestureRecognizer) {
if let tag = sender.view?.tag {
println(tag)
}
}
Try following code. 尝试以下代码。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.view.userInteractionEnabled = true
var tapGesture = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
self.view.tag = 101
self.view.addGestureRecognizer(tapGesture)
}
func handleTap(sender:UITapGestureRecognizer) {
if let tag = sender.view?.tag {
println(tag)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.