Search code examples
iphonecore-animation

CATransaction (still) Not Animating


I have a problem very similar to this one :

CATransaction Not Animating

I'm just trying to animate a view layer using CATransaction. My problem is that the transform is applied to the view immediatly.

I tried to perform the animation using performSelector:withObject:afterDelay: without success.

Here is my code :

- (void)viewDidLoad {
    [super viewDidLoad];

 view = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease];
 view.backgroundColor = [UIColor blackColor];
 [self.view addSubview:view];

 [self performSelector:@selector(animateView) withObject:nil afterDelay:0.1];
}

-(void) animateView {
 [CATransaction begin];
 [CATransaction setValue:[NSNumber numberWithFloat:3.0f] forKey:kCATransactionAnimationDuration];
    CALayer *layer = view.layer;
    layer.position = CGPointMake(20, 
         300);
    CATransform3D transform = CATransform3DMakeScale(2.0f, 2.0f, 1.0f);
    transform = CATransform3DRotate(transform, acos(-1.0f)*1.5f, 1.5f, 1.5f, 1.5f);
    layer.transform = transform;
    [CATransaction commit];
}

Does anybody knows what is going wrong ?

Thanks, Vincent.


Solution

  • when animating a view's backing layer, you need to be inside a UIView animation block, not just a CATransaction:

    [UIView beginAnimations:nil context:NULL];
    // ... your animation code
    [UIView commitAnimations];