79218710

Date: 2024-11-23 20:02:31
Score: 1.5
Natty:
Report link

@Versus answer works, but has a few peculiar behaviors. It causes CustomView to intercept taps outside its frame, and it prevents buttons in the cover view (view5) from working. This version of hitTest fixes those cases:

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    if view1.point(inside: self.convert(point, to: view1), with: event) {
        // inside view1
        return view1
    } else if self.point(inside: point, with: event) {
        // inside CustomView (but outside view1)
        return super.hitTest(point, with: event)  // superview's tapped view  
    } else {
        // outside CustomView
        return nil
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Versus
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: P. Stern