【问题标题】:UICollectionViewCell signal to UICollectionView didSelectUICollectionViewCell 向 UICollectionView didSelect 发出信号
【发布时间】:2015-10-01 22:01:09
【问题描述】:

在我的UICollectionView 中的UICollectionViewCells 之上,我覆盖了一个拦截触摸的UIButton,这样我就可以更细致地响应触摸事件。问题是现在集合视图不再收到didSelectItemAtIndexPath 消息。 (出于显而易见的原因......按钮已经吸收了触摸并且没有向集合视图发出该项目被选中的信号。)

有没有办法向集合视图发出单元格被选中的信号?我见过类似的问题,但似乎没有一个给出令人信服的答案。

【问题讨论】:

    标签: ios swift uikit uicollectionview uicollectionviewcell


    【解决方案1】:

    您可以覆盖 UIView [和子类] 上的 pointInside:withEvent: 消息并返回 false 以继续传播触摸事件。

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/pointInside:withEvent:

    class PassThroughButton: UIButton {
      override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
        // do something
        // then continue event propigation
        return false
      }
    }
    

    【讨论】:

    • 我真的很喜欢这个解决方案——不仅因为它解决了我的问题,而且我学会了如何传播触摸。谢谢!
    猜你喜欢
    • 2019-01-06
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    相关资源
    最近更新 更多