微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决覆盖单元格中的触摸后,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)
    ....

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。