【问题标题】:iOS TableView Long press Gesture going to didselectrowatIndexpathiOS TableView长按手势去didselectrowatIndexpath
【发布时间】:2018-01-18 08:54:22
【问题描述】:

伙计们,我有显示图像的表格视图,因此对于任何图像点击都会在

中打开图像

didselectrowatIndexpath

所以我想添加一个长按手势所以我添加了

let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:))) 
cell.baseview.addGestureRecognizer(longPressGesture) 

但是每次我按住图像时,它都会使用 didselectrowat 方法并打开图像,而不是使用 longpressed 方法。 长按手势动作有什么我应该改变的吗?

【问题讨论】:

标签: ios long-press


【解决方案1】:

这是 Apple 对您问题的回答。

Managing Selections (Responding to Selections)
如果触摸发生在嵌入在行中的控件中,它可以 响应控件发送的动作消息。

Understanding Responders and the Responder Chain
UIKit 将大多数事件定向到应用程序中最合适的响应器对象。如果该对象不处理该事件,UIKit 会将其转发给活动响应者链中的下一个响应者,这是您应用的响应者对象的动态配置。

解决方案:
您对图像的用户交互有疑问。在图像视图上启用用户交互。

cell.baseview.isUserInteractionEnabled = true

【讨论】:

  • 工作就像一个伟大的魅力
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多