Last active
December 14, 2020 11:07
-
-
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.
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 | |
/** | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked for Swift 3. Sorry, gists don't allow for Pull Requests :(
https://gist.github.com/siberian1967/ab1e15f46b5ed30d0e3060079f090ae8