1
tap.addTarget(self, action: "handleTap:")
self.view.addGestureRecognizer(tap)
我想訪問的view
的view.tag
財產handleTap
方法。 那麼如何傳遞「tap」作爲handleTap參數的UIView?
謝謝。
tap.addTarget(self, action: "handleTap:")
self.view.addGestureRecognizer(tap)
我想訪問的view
的view.tag
財產handleTap
方法。 那麼如何傳遞「tap」作爲handleTap參數的UIView?
謝謝。
func handleTap(sender:UITapGestureRecognizer) {
if let tag = sender.view?.tag {
println(tag)
}
}
請嘗試下面的代碼。
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)
}
}