Created
July 19, 2012 19:58
-
-
Save badeen/3146387 to your computer and use it in GitHub Desktop.
Animation applies a y translation transform. Why?
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)animatePhotosIn | |
{ | |
CAKeyframeAnimation *userPhotoAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; | |
userPhotoAnim.values = [self photoTransformValuesWithMultiplier:1.0]; | |
CAKeyframeAnimation *matchPhotoAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; | |
matchPhotoAnim.values = [self photoTransformValuesWithMultiplier:-1.0]; | |
NSArray *photoAnims = [NSArray arrayWithObjects:userPhotoAnim, matchPhotoAnim, nil]; | |
for (CAKeyframeAnimation *photoAnim in photoAnims) { | |
photoAnim.calculationMode = kCAAnimationCubic; | |
photoAnim.duration = 1.0; | |
} | |
[userImageView.layer addAnimation:userPhotoAnim forKey:@"userPhotoAnim"]; | |
[matchImageView.layer addAnimation:matchPhotoAnim forKey:@"matchPhotoAnim"]; | |
} | |
- (NSArray *)photoTransformValuesWithMultiplier:(CGFloat)multiplier | |
{ | |
NSArray *translations = [self photoTranslationValuesWithMultiplier:-multiplier]; | |
NSArray *rotations = [self photoRotationValuesWithMultiplier:multiplier]; | |
NSMutableArray *combinedTransforms = [NSMutableArray arrayWithCapacity:[translations count]]; | |
for (NSInteger i = 0; i < [translations count]; i ++) { | |
CATransform3D translation = [(NSValue *)[translations objectAtIndex:i] CATransform3DValue]; | |
CATransform3D rotation = [(NSValue *)[rotations objectAtIndex:i] CATransform3DValue]; | |
CATransform3D combinedTransform = CATransform3DConcat(translation, rotation); | |
[combinedTransforms addObject:[NSValue valueWithCATransform3D:combinedTransform]]; | |
} | |
return combinedTransforms; | |
} | |
- (NSArray *)photoTranslationValuesWithMultiplier:(CGFloat)multiplier | |
{ | |
return [NSArray arrayWithObjects: | |
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(multiplier * 200.0, 0, 0)], | |
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(multiplier * -150.0, 0, 0)], | |
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(multiplier * 0, 0, 0)], | |
nil]; | |
} | |
- (NSArray *)photoRotationValuesWithMultiplier:(CGFloat)multiplier | |
{ | |
return [NSArray arrayWithObjects: | |
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4 / 2.0 * multiplier, 0, 0, 1)], | |
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4 * multiplier, 0, 0, 1)], | |
[NSValue valueWithCATransform3D:CATransform3DMakeRotation(0 * multiplier, 0, 0, 1)], | |
nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment