想要实现的效果
点击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.point(inside: p2, with: event)
}
if subview != nil {
return self.collection.hitTest(p, with: event)
}else {
return self
}
}
return self
}