Created
June 30, 2014 06:54
-
-
Save jhildensperger/efcdbfc395343f4992d7 to your computer and use it in GitHub Desktop.
Method to shake a view with a completion block
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
- (void)shakeView:(UIView *)view completion:(void (^)(void))completion { | |
[UIView animateKeyframesWithDuration:.5 delay:0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{ | |
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:.25 animations:^{ | |
view.transform = CGAffineTransformMakeTranslation(-5, 0); | |
}]; | |
[UIView addKeyframeWithRelativeStartTime:.25 relativeDuration:.25 animations:^{ | |
view.transform = CGAffineTransformMakeTranslation(5, 0); | |
}]; | |
[UIView addKeyframeWithRelativeStartTime:.5 relativeDuration:.25 animations:^{ | |
view.transform = CGAffineTransformMakeTranslation(-5, 0); | |
}]; | |
[UIView addKeyframeWithRelativeStartTime:.75 relativeDuration:.25 animations:^{ | |
view.transform = CGAffineTransformMakeTranslation(0, 0); | |
}]; | |
} completion:^(BOOL finished) { | |
if (finished && completion) { | |
completion(); | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment