超出view部分的事件响应

2023-08-16  本文已影响0人  太平洋_cfd2

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)
    }
上一篇 下一篇

猜你喜欢

热点阅读