tableView 与collectionView嵌套 coll

2018-05-25  本文已影响0人  思绪飘零ing

这里就要说到 iOS 的响应链iOS 的所有点击方法 都是用响应链 传递到最底层的 所以可以截取响应链 让colllectionView失效

用在tablviewCell里面即可

//OC 写法

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{  

UIView *view = [super hitTest:point withEvent:event];  

if ([view isKindOfClass:[UICollectionView class]]) {  

return self;  

    }  

return [super hitTest:point withEvent:event];  

//swift4.0 写法

// 修改 tablview 和collection 嵌套 导致tablview cell点击不到

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {

      let view = super.hitTest(point, with: event)

        if let touchView = view {

            if touchView.isKind(of: UICollectionView.self ){

                return self

            }

        }

        return super.hitTest(point, with: event)

    }

上一篇 下一篇

猜你喜欢

热点阅读