实现 iOS UICollectionView的事件透传

比如当前的collectionViewA(蓝色), 还有一个collectionViewCellA(红色),collectionViewCellA(红色)里面有一个collectionViewB(绿色),

collectionViewCellB(绿色)里面有两个collectionViewCellB1(白色)、collectionViewCellB2(白色)

 

点击collectionViewCellA(红色) 弹出点击collectViewAcell

点击collectionViewB(绿色) 也弹出点击collectViewAcell 

点击collectionViewCellB1(白色)、collectionViewCellB2(白色) 弹出点击collectViewBcell

 

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    CGPoint btnPointInA = [self.collectView convertPoint:point fromView:self];
    if ([self.collectView pointInside:btnPointInA withEvent:event]) {
        for (UIView *subView in self.collectView.subviews) {
            CGPoint subViewPoint = [subView convertPoint:point fromView:self];
            if ([subView pointInside:subViewPoint withEvent:event]) {
                return subView;
            }
        return self;
    }
    // 否则,返回默认处理
    return [super hitTest:point withEvent:event];
}
posted @ 2019-09-06 12:23  喜狼狼  阅读(1156)  评论(0编辑  收藏  举报