-
-
Save fewlinesofcode/b63b705d0d86ac68f27ed0c192b797cc to your computer and use it in GitHub Desktop.
Make subviews touchable even if it is outside its superview 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
// Make subviews touchable even if it is outside its superview bounds. | |
// ** Add more views here ** | |
lazy var touchableViews: [UIView] = { | |
return [self.voteUpButton, self.voteDownButton, self.authorDetailButton] | |
}() | |
// Boilerplate | |
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? { | |
for view in touchableViews { | |
if let v = view.hitTest(view.convertPoint(point, fromView: self), withEvent: event) { | |
return v | |
} | |
} | |
return super.hitTest(point, withEvent: event) | |
} | |
// Boilerplate | |
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool { | |
if super.pointInside(point, withEvent: event) { | |
return true | |
} | |
for view in touchableViews { | |
return !view.hidden && view.pointInside(view.convertPoint(point, fromView: self), withEvent: event) | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment