需求:
項(xiàng)目里有tableview里面嵌套collectionView,collectionView不需要點(diǎn)擊事件,實(shí)現(xiàn)的效果是點(diǎn)擊collectionView里面,觸發(fā)的是tableView的點(diǎn)擊事件
在TableViewCell里面寫上如下代碼即可
//點(diǎn)擊事件穿透,不響應(yīng)collectionView的點(diǎn)擊事件
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let view = super.hitTest(point, with: event)
if let bool = (view?.isKind(of: UICollectionView.self)) {
if bool {
return self
}
}
return view
}