【问题标题】:Swift CollectionView didSelectItemAt no longer working after overriding touch in cell覆盖单元格中的触摸后,Swift CollectionView didSelectItemAt 不再工作
【发布时间】:2020-10-11 20:38:12
【问题描述】:

我想在我的CustomCollectionViewCell 上添加一个tapAnimation,所以我在class 中添加了这些行:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    UIView.animate(withDuration: 0.05, delay: 0, options: .curveEaseInOut) {
        self.theView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
    }
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseInOut) {
        self.theView.transform = CGAffineTransform(scaleX: 1, y: 1)
    }
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    UIView.animate(withDuration: 0.1) {
        self.theView.transform = CGAffineTransform(scaleX: 1, y: 1)
    }
}

theView 几乎就是这里的整个cell。但是,添加此内容后,我的collectionView 中的didSelectItemAt 不再触发。知道我在这里做错了什么吗?它可以在没有override-sn-ps 的情况下工作。

补充:我实际上希望有一个像 App-Store 一样的动画(只有点击动画,没有过渡!)

如果您需要更多信息,请告诉我!

【问题讨论】:

    标签: ios swift uicollectionview uicollectionviewcell


    【解决方案1】:
    • 覆盖时忘记调用super

    例如:

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        ....
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-05
      • 2019-09-29
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多