iOS TableView 长按手势去 didselectrowatIndexpath
iOS TableView Long press Gesture going to didselectrowatIndexpath
伙计们,我有 table 显示图像的视图,因此对于任何图像点击都会在
中打开图像
didselectrowatIndexpath
所以我想添加一个长按手势所以我添加了
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:)))
cell.baseview.addGestureRecognizer(longPressGesture)
但每次我按住图像时,它都会使用 didselectrowat 方法打开图像,而不是使用长按方法。
对于长按手势动作,我应该改变什么吗?
这是 Apple 对您问题的回答。
Managing Selections (Responding to Selections)
If the touch occurred in a control embedded in the row, it could
respond to the action message sent by the control.
Understanding Responders and the Responder Chain
UIKit directs most events to the most appropriate responder object in your app. If that object does not handle the event, UIKit forwards it to the next responder in the active responder chain, which is a dynamic configuration of your app’s responder objects.
解法:
您遇到图像的用户交互问题。在图像视图上启用用户交互。
cell.baseview.isUserInteractionEnabled = true
伙计们,我有 table 显示图像的视图,因此对于任何图像点击都会在
中打开图像didselectrowatIndexpath
所以我想添加一个长按手势所以我添加了
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:)))
cell.baseview.addGestureRecognizer(longPressGesture)
但每次我按住图像时,它都会使用 didselectrowat 方法打开图像,而不是使用长按方法。 对于长按手势动作,我应该改变什么吗?
这是 Apple 对您问题的回答。
Managing Selections (Responding to Selections)
If the touch occurred in a control embedded in the row, it could respond to the action message sent by the control.Understanding Responders and the Responder Chain
UIKit directs most events to the most appropriate responder object in your app. If that object does not handle the event, UIKit forwards it to the next responder in the active responder chain, which is a dynamic configuration of your app’s responder objects.
解法:
您遇到图像的用户交互问题。在图像视图上启用用户交互。
cell.baseview.isUserInteractionEnabled = true