實現 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