Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created November 16, 2020 16:14
Show Gist options
  • Save SergLam/393af37e379db2d5338ab38151378277 to your computer and use it in GitHub Desktop.
Save SergLam/393af37e379db2d5338ab38151378277 to your computer and use it in GitHub Desktop.
Pass touches over view bounds
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