Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Created March 4, 2016 12:55
Show Gist options
  • Save NSExceptional/4afb14cf233b043dad7f to your computer and use it in GitHub Desktop.
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.
@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