首页 > 解决方案 > Child UIViewController view prevents container UIViewController views from receiving touch events

问题描述

I have a map and some buttons inside main UIViewController and a popup view inside child UIViewController. The problem is that main view of child UIViewController preventing main buttons and map from receiving any touch event!

the structure as following:

Edit:
this code pass all events but I don't need to stop popup UIView and buttons events

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
print("Passing all touches to the next view (if any), in the view stack.")
return false

}

标签: iosswift

解决方案


based on @BencePattogato answer, this code fixed my issue. thanks

class UnTouchableView: UIView {
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        return subviews.contains(where: {
            !$0.isHidden && $0.point(inside: self.convert(point, to: $0), with: event)
        })
    }
}

推荐阅读