美文网首页
超出view部分的事件响应

超出view部分的事件响应

作者: 太平洋_cfd2 | 来源:发表于2023-08-16 14:23 被阅读0次

https://juejin.cn/post/6844903647306874888

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if !self.point(inside: point, with: event) {
            if let contentV = subviews.last?.subviews.last {
                for view in contentV.subviews {
                    if view == rightImgView {
                        let point2 = convert(point, to: view)
                        // 看准位置是frame或者bounds
                        if CGRectContainsPoint(view.bounds, point2) {
                            return view
                        }
                    }
                }
            }
        }

        return super.hitTest(point, with: event)
    }

相关文章

网友评论

      本文标题:超出view部分的事件响应

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