实现 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];
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM