点击事件处理

想要实现的效果
点击CollectionCell走func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) ,其他的则走父控件的方法,在以下代码里,self代表父控件(自行替换)

override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let p = self.convert(point, to: self.collection)
if self.collection.point(inside: p, with: event) {
let subview = self.collection.subviews.first {
let p2 = self.convert(point, to: 0) return0.point(inside: p2, with: event)
}
if subview != nil {
return self.collection.hitTest(p, with: event)
}else {
return self
}
}
return self
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容