美文网首页
tableView 与collectionView嵌套 coll

tableView 与collectionView嵌套 coll

作者: 思绪飘零ing | 来源:发表于2018-05-25 11:39 被阅读0次

这里就要说到 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)

    }

相关文章

网友评论

      本文标题:tableView 与collectionView嵌套 coll

      本文链接:https://www.haomeiwen.com/subject/pbmyjftx.html