美文网首页
iOS 子视图超出父视图范围并响应事件

iOS 子视图超出父视图范围并响应事件

作者: lczalh | 来源:发表于2020-10-27 18:18 被阅读0次

在父视图中重写 func point(inside point: CGPoint, with event: UIEvent?) -> Bool

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        if self.bounds.contains(point) {
            return true
        }
        for subView:UIView in self.subviews {
            let hitPoint = self.convert(point, to: subView)
            if subView.bounds.contains(hitPoint) {
                return true
            }
        }
        return false
    }

相关文章

网友评论

      本文标题:iOS 子视图超出父视图范围并响应事件

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