Skip to content

Instantly share code, notes, and snippets.

@danielgarbien
Created October 24, 2023 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgarbien/3cb1aa3545a17e71cc165703429c6d61 to your computer and use it in GitHub Desktop.
Save danielgarbien/3cb1aa3545a17e71cc165703429c6d61 to your computer and use it in GitHub Desktop.
class TouchGoThroughView: UIView {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
super.point(inside: point, with: event) && pointInsideVisibleSubviews(point, with: event)
}
}
extension UIView {
func pointInsideVisibleSubviews(_ point: CGPoint, with event: UIEvent?) -> Bool {
let visibleSubviews = subviews.filter {
$0.isHidden == false && $0.alpha > 0
}
for subview in visibleSubviews {
let pointInSubview = convert(point, to: subview)
if subview.point(inside: pointInSubview, with: event) {
return true
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment