Last active
August 29, 2015 14:00
-
-
Save shaps80/11262508 to your computer and use it in GitHub Desktop.
Added transitions
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
@interface UIView (SPXAdditions) | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations; | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration delay:(CGFloat)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion; | |
+ (void)animate:(BOOL)shouldAnimate duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion; | |
+ (void)transition:(BOOL)shouldTransition fromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion; | |
+ (void)transition:(BOOL)shouldTransition withView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion; | |
@end |
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
#import "UIView+SPXAdditions.h" | |
@implementation UIView (SPXAdditions) | |
#pragma mark - Transition If | |
+ (void)transition:(BOOL)shouldTransition withView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion | |
{ | |
[UIView transitionWithView:view duration:shouldTransition ? duration : 0 options:options animations:animations completion:completion]; | |
} | |
+ (void)transition:(BOOL)shouldTransition fromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion | |
{ | |
[UIView transitionFromView:fromView toView:toView duration:shouldTransition ? duration : 0 options:options completion:completion]; | |
} | |
#pragma mark - Animate If | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations | |
{ | |
[self animateWithDuration:duration delay:0 options:0 animations:animations completion:nil]; | |
} | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion | |
{ | |
[self animate:shouldAnimate duration:duration delay:0 options:0 animations:animations completion:completion]; | |
} | |
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration delay:(CGFloat)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion | |
{ | |
[UIView animateWithDuration:duration delay:delay options:options animations:animations completion:completion]; | |
} | |
+ (void)animate:(BOOL)shouldAnimate duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion | |
{ | |
[UIView animateWithDuration:shouldAnimate ? duration : 0 delay:delay usingSpringWithDamping:dampingRatio initialSpringVelocity:velocity options:options animations:animations completion:completion]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment