【问题标题】:UITapGesture on UIImageview not WorkingUIImageview上的UITapGesture不起作用
【发布时间】:2016-04-08 09:11:18
【问题描述】:

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

当我运行并点击图像时,什么也没发生。谁能帮帮我。

【问题讨论】:

  • 尝试在 UIImageView 上启用用户交互...在 Storyboard 或 userInteractionEnabled = true
  • 哦,是的,它成功了。但是如何准备Segue? @Byron Coetsee
  • 别忘了调用 super.viewDidLoad()

标签: ios objective-c iphone xcode swift


【解决方案1】:

在你的图片上添加userInteractionEnabledtrue 并尝试

brandMenuContactImage.userInteractionEnabled  = true

objective-C

 brandMenuContactImage.userInteractionEnabled  = YES;

更新

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

【讨论】:

  • 如果要传数据怎么办?
  • 你可以通过,你可以使用sender.view.tag获取项目,然后你就可以通过了
  • 如何传递变量?可以举个例子吗?
  • @lamfete - 可以更新您需要哪种类型的问题,例如,如果我点按您想要执行的图像
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-09
  • 2012-05-14
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多