我正在尝试使用UITapGesture将UIImage作为按钮。
let contactSegueIdentifier = "showContactSegue"
override func viewDidLoad() {
initTapGestureRec()
}
func initTapGestureRec() {
let tapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("recognizeTapGesture:"))
brandMenuContactImage.addGestureRecognizer(tapGesture)
}
func recognizeTapGesture(sender: UIGestureRecognizer) {
self.performSegueWithIdentifier(contactSegueIdentifier, sender: self)
}
当我跑步并点按图片时,没有任何反应。任何人都可以帮助我。
答案 0 :(得分:3)
在您的图片上添加userInteractionEnabled
true并尝试
brandMenuContactImage.userInteractionEnabled = true
<强>目标-C 强>
brandMenuContactImage.userInteractionEnabled = YES;
<强>更新强>
override func viewDidLoad() {
brandMenuContactImage.userInteractionEnabled = true
initTapGestureRec()
}