0

I'm trying to implement the following animation:

    yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement
// animate it to the identity transform (100% scale)
yourSubView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// if you want to do something once the animation finishes, put it here
}];

combined with some movement of the subview. I know in core animation you can combine animations but how can you do that in UIView animation?

Can I translate this code from UIView animation to Core animation?

yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement
// animate it to the identity transform (100% scale)
yourSubView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// if you want to do something once the animation finishes, put it here
}];
Juan
  • 627
  • 2
  • 9
  • 27

1 Answers1

2

You can combine animations by changing more than one animatable property. For example, you can also set yourSubView.alpha, then change the alpha within the animation block. It will combine the scale and alpha change together.

To do a simple translation, try this in your animation block:

yourSubView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100.0, 100.0); 

this should set the scale back to identity along with moving 100px in x and y direction.

For Core Animation, this Grouping two Core Animations with CAAnimationGroup causes one CABasicAnimation to not run should get you started. You'll use a CAAnimationGroup to combine multiple animations, and can do pretty fancy stuff including 3D rotation.

Scaling:

CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
[scale setValues:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.01f],[NSNumber numberWithFloat:1.0f],nil]];
[scale setKeyTimes:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.4f],nil]];

[mySubview.layer addAnimation:scale forKey:@"myScale"];
Community
  • 1
  • 1
CSmith
  • 13,318
  • 3
  • 39
  • 42
  • how can convert code to core animation:yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01); [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ //change time duration according to requirement // animate it to the identity transform (100% scale) yourSubView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished){ // if you want to do something once the animation finishes, put it here }]; – Juan Aug 27 '12 at 20:18