Search code examples
iphoneiosanimationcore-animation

Combining animations on UIView and subiview's CALayer?


I'm animating a UIView transition like so:

UIView *areaView = areaController.view;
[areaController viewWillAppear:YES];

UIView *subView = self.customView.subView;
UIButton *button = customView.button; // button is a subview of customView.subView

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:subView cache:YES];

[button removeFromSuperview];
[subView addSubview:areaView];
[areaController viewDidAppear:YES];


[UIView commitAnimations];

[self.areaController start];  // areaController starts the animation of the CALayer, see below

This flips the new view, areaView from "behind" the button just fine, but in areaView there's another subview which is animating it's CALayer:

CATransform3D rotate = CATransform3DMakeRotation(angle, 1, 0, 0);

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];

animation.toValue = [NSValue valueWithCATransform3D:rotate];
animation.duration = .08;
animation.delegate = self;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;   

[layer addAnimation:animation forKey:@"transform"];

My question is:

How do I make both these animations animate in parallell?

Currently, the animation on the CALayer starts when calling [self.areaController start];, but the result is not visible until the transition on the superview is finished. Should I somehow use an animation group with the UIView's layer?


Solution

  • I think you can't do these at the same time. What you can do is do the first animation also using the CATransform3D, then they will occur at the same time. This is an old post though so maybe you've already solved the issue.