Skip to content

Instantly share code, notes, and snippets.

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 breeno/852826 to your computer and use it in GitHub Desktop.
Save breeno/852826 to your computer and use it in GitHub Desktop.
Sequenced animations with blocks
#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