Skip to content

Instantly share code, notes, and snippets.

@maxcampolo
Last active December 14, 2020 11:07
Show Gist options
  • Save maxcampolo/ee89fea101b564b7756e to your computer and use it in GitHub Desktop.
Save maxcampolo/ee89fea101b564b7756e to your computer and use it in GitHub Desktop.
UIView subclass that is transparent to all touch events besides those on eligible child views.
import UIKit
/**
UIView subclass that is transparent to all touch events besides those on eligible child views.
*/
class TKPassThroughView: UIView {
// MARK - Touch Handling
/**
Override this point and determine if any of the subviews of our transparent view are the ones being tapped. If that is the case, handle those touches otherwise pass the touch through.
*/
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
for subview in subviews as [UIView] {
if !subview.hidden && subview.alpha > 0 && subview.userInteractionEnabled && subview.pointInside(convertPoint(point, toView: subview), withEvent: event) {
return true
}
}
return false
}
}
@siberian1967
Copy link

Forked for Swift 3. Sorry, gists don't allow for Pull Requests :(

https://gist.github.com/siberian1967/ab1e15f46b5ed30d0e3060079f090ae8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment