UIImageview上的UITapGesture无法正常工作

时间:2016-04-08 09:11:18

标签: ios objective-c iphone xcode swift

我正在尝试使用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)
}

当我跑步并点按图片时,没有任何反应。任何人都可以帮助我。

1 个答案:

答案 0 :(得分:3)

在您的图片上添加userInteractionEnabled true并尝试

brandMenuContactImage.userInteractionEnabled  = true

<强>目标-C

 brandMenuContactImage.userInteractionEnabled  = YES;

<强>更新

override func viewDidLoad() {
  brandMenuContactImage.userInteractionEnabled  = true
initTapGestureRec()
}