-
-
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.
This file contains hidden or 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
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