Created
October 3, 2011 18:35
-
-
Save jamztang/1259860 to your computer and use it in GitHub Desktop.
Adding fade out effect on -[UIView removeFromSuperview]
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
// | |
// UIView+JTRemoveAnimated.h | |
// | |
// Created by james on 9/1/11. | |
// http://ioscodesnippet.tumblr.com/ | |
// | |
@interface UIView (JTRemoveAnimated) | |
- (void)removeFromSuperviewAnimated; | |
@end |
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
// | |
// UIView+JTRemoveAnimated.m | |
// | |
// Created by james on 9/1/11. | |
// http://ioscodesnippet.tumblr.com/ | |
// | |
// Updated at 10/12/12 for ARC projects | |
#import "UIView+JTRemoveAnimated.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation UIView (JTRemoveAnimated) | |
// remove static analyser warnings | |
#ifndef __clang_analyzer__ | |
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { | |
if ([animationID isEqualToString:@"fadeout"]) { | |
// Restore the opacity | |
CGFloat originalOpacity = [(__bridge_transfer NSNumber *)context floatValue]; | |
self.layer.opacity = originalOpacity; | |
[self removeFromSuperview]; | |
} | |
} | |
- (void)removeFromSuperviewAnimated { | |
[UIView beginAnimations:@"fadeout" context:(__bridge_retained void *)[NSNumber numberWithFloat:self.layer.opacity]]; | |
[UIView setAnimationDuration:0.3]; | |
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; | |
[UIView setAnimationDelegate:self]; | |
self.layer.opacity = 0; | |
[UIView commitAnimations]; | |
} | |
#endif | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment