ios - cellView 外的按钮没有触摸事件
ios - button out of cellView don't get touch event
我有一个 table 视图,我将中间的 cellView 放在前面。该视图有一个显示在其上方的子视图,与前一个单元格重叠。当我点击这个子视图时,其中的按钮没有获得触摸事件。相反,显示在按钮下方的前一个单元格获得单元格选择。
无论我将下面的单元格的 UserInteractionEnable 设置为 true 还是 false 都不会改变行为。
----------------------> z-index
cell 1
|
| button within cell 2
| cell 2 |
|
|
|
如何让按钮获得触摸事件?
在你的 UITableViewCell
子类中,你应该用类似的东西覆盖 pointInside
:
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
{
if self.isSelected
{
return self.button.frame.contains(point) || self.frame.contains(point)
}
return super.point(inside: point, with: event)
}
我有一个 table 视图,我将中间的 cellView 放在前面。该视图有一个显示在其上方的子视图,与前一个单元格重叠。当我点击这个子视图时,其中的按钮没有获得触摸事件。相反,显示在按钮下方的前一个单元格获得单元格选择。
无论我将下面的单元格的 UserInteractionEnable 设置为 true 还是 false 都不会改变行为。
----------------------> z-index
cell 1
|
| button within cell 2
| cell 2 |
|
|
|
如何让按钮获得触摸事件?
在你的 UITableViewCell
子类中,你应该用类似的东西覆盖 pointInside
:
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
{
if self.isSelected
{
return self.button.frame.contains(point) || self.frame.contains(point)
}
return super.point(inside: point, with: event)
}