覆盖单元格中的触摸后,Swift CollectionView didSelectItemAt不再起作用

问题描述

我想在tapAnimation上放一个CustomCollectionViewCell,所以我在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,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。但是,添加此选项后,我的didSelectItemAt中的collectionView将不再触发。知道我在做什么错吗?它不带override代码段。

添加:我实际上想在App Store中有一个动画(仅点击动画,而不是过渡动画!)

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

解决方法

  • 您在覆盖时忘记致电super

例如:

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