Created
March 4, 2016 12:55
-
-
Save NSExceptional/4afb14cf233b043dad7f 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 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
@implementation VanishingView | |
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
UITouch *t = touches.allObjects.firstObject; | |
self.alpha = 1 - t.force/t.maximumPossibleForce; | |
if (t.force == t.maximumPossibleForce) { | |
[self removeFromSuperview]; | |
} | |
} | |
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
[UIView animateWithDuration:.1 animations:^{ | |
self.alpha = 1; | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment