Skip to content

Instantly share code, notes, and snippets.

@ondrejmirtes
Created December 26, 2013 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ondrejmirtes/8134202 to your computer and use it in GitHub Desktop.
Save ondrejmirtes/8134202 to your computer and use it in GitHub Desktop.
Animate sequence of animations
#import <Foundation/Foundation.h>
@interface AnimateSequence : NSObject
+ (void)animate:(NSArray*)blocks duration:(NSTimeInterval)duration;
@end
#import "AnimateSequence.h"
@implementation AnimateSequence
+ (void)animate:(NSArray*)blocks duration:(NSTimeInterval)duration
{
[AnimateSequence animate:blocks duration:duration index:0];
}
+ (void)animate:(NSArray *)blocks duration:(NSTimeInterval)duration index:(NSUInteger)i
{
if (i >= blocks.count) {
return;
}
[UIView animateWithDuration:duration animations:[blocks objectAtIndex:i] completion:^(BOOL finished) {
[AnimateSequence animate:blocks duration:duration index:(i + 1)];
}];
}
@end
- (void)bounce
{
NSMutableArray* blocks = [NSMutableArray new];
[blocks addObject:^{
[self.contentScrollView setContentOffset:(CGPoint){34.0, 0.0}];
}];
[blocks addObject:^{
[self.contentScrollView setContentOffset:(CGPoint){self.closedXOffset, 0.0}];
}];
[blocks addObject:^{
[self.contentScrollView setContentOffset:(CGPoint){12.0, 0.0}];
}];
[blocks addObject:^{
[self.contentScrollView setContentOffset:(CGPoint){self.closedXOffset, 0.0}];
}];
[AnimateSequence animate:blocks duration:0.11f];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment