views:

65

answers:

1

I have a subclassed UIView that is comprised of several layers (mostly CAShapeLayers with a few CATextLayers). The problem I have is that if I animate resizing the UIView using an animation block (beginAnimations, commitAnimations) and relayout the sublayers in the overridden layoutSubviews, then the layers are not animated with the UIView.

Below is my code to animate the frame of the UIView:

miniView.backgroundColor = [UIColor orangeColor];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatCount:MAXFLOAT];
[UIView setAnimationRepeatAutoreverses:YES];

miniView.frame = newFrame;

[UIView commitAnimations];

So the problem is that the view is properly animated but the sublayers are not. I can see the view growing and shrinking but the sublayers grow immediately and then stay the new larger size. What is the best way to resize the sublayers of a view when the view is resized? And how do I make those animate in the same way with the parent view?

A: 

I would need to see more code to really fix the problem, however you can try to animate miniView's layer instead of its view.

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:1.0];
// additional setup...

[miniView.layer layoutIfNeeded];
[miniView.layer addAnimation:animation forKey:@"whateverYouWant"];

Instead of using UIKit animation this should be more flexible once you get the hang of it.

Brandon Emrich