Created
March 3, 2011 14:16
-
-
Save breeno/852826 to your computer and use it in GitHub Desktop.
Sequenced animations with blocks
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+ShakeAnimationAdditions.h" | |
#import "AnimationSequencer.h" | |
@implementation UIView (ShakeAnimationAdditions) | |
-(void) performShakeAnimation | |
{ | |
AnimationSequencer *sequencer = [AnimationSequencer sequencer]; | |
sequencer.interAnimationInterval = 0.0; | |
sequencer.sequenceDuration = 0.05; | |
const CGPoint originalCenter = self.center; | |
const CGFloat kOffset = 60; | |
// 1/2 to right | |
[sequencer addAnimationBlock:^(id object) | |
{ | |
self.center = CGPointMake(self.center.x + (kOffset / 2.0), self.center.y); | |
}]; | |
// back and forth 3 times | |
const NSInteger kShakeCount = 3; | |
for( NSInteger index=0; index<kShakeCount; index++ ) | |
{ | |
[sequencer addAnimationBlock:^(id object) | |
{ | |
self.center = CGPointMake( originalCenter.x - kOffset, originalCenter.y); | |
}]; | |
[sequencer addAnimationBlock:^(id object) | |
{ | |
self.center = CGPointMake( originalCenter.x + kOffset, originalCenter.y); | |
}]; | |
} | |
// back to the left (original center) | |
[sequencer addAnimationBlock:^(id object) | |
{ | |
self.center = originalCenter; | |
}]; | |
[sequencer start]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment