Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/11262508 to your computer and use it in GitHub Desktop.
Save shaps80/11262508 to your computer and use it in GitHub Desktop.
Added transitions
@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
#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