Created
November 16, 2020 16:14
-
-
Save SergLam/393af37e379db2d5338ab38151378277 to your computer and use it in GitHub Desktop.
Pass touches over view bounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class HitTestUIView: UIView { | |
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { | |
if clipsToBounds || isHidden || alpha == 0 { | |
return nil | |
} | |
for subview in subviews.reversed() { | |
let subPoint = subview.convert(point, from: self) | |
if let result = subview.hitTest(subPoint, with: event) { | |
return result | |
} | |
} | |
return super.hitTest(point, with: event) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment