美文网首页
UICollectionView点击空白处,将点击事件传递到su

UICollectionView点击空白处,将点击事件传递到su

作者: _YyXia | 来源:发表于2020-08-21 10:12 被阅读0次

在加载scrollView的类中添加如下代码

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    guard self.point(inside: point, with: event) else {
        return super.hitTest(point, with: event)
    }
    let newPoint = convert(point, to: collectionView)
    if collectionView.point(inside: newPoint, with: event) {
        for subView in collectionView.visibleCells {
            let subViewPoint = convert(point, to: subView)
            if subView.point(inside: subViewPoint, with: event) {
                return subView
            }
        }
    }
    return self
}

相关文章

网友评论

      本文标题:UICollectionView点击空白处,将点击事件传递到su

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