Skip to content

Instantly share code, notes, and snippets.

@buddax2
Forked from NSExceptional/VanishingView.m
Last active March 4, 2016 14:24
Show Gist options
  • Save buddax2/e60b8284fc9be4e713d3 to your computer and use it in GitHub Desktop.
Save buddax2/e60b8284fc9be4e713d3 to your computer and use it in GitHub Desktop.
A UIView subclass that fades away more the harder you press on it, and eventually disappears if you press hard enough. iOS 9 only, of course.
extension UIView {
override public func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
self.alpha = 1 - touch.force / touch.maximumPossibleForce
if touch.force == touch.maximumPossibleForce {
self.removeFromSuperview()
}
}
}
override public func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
UIView.animateWithDuration(1, animations: {
self.alpha = 1;
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment