Search code examples
objective-ccore-animation

CATransaction duration not working


I set a few CALayer transform and bounds modifications, within a CATransaction. However, regardless the method I use (key-value, setAnimationDuration) there is no animation, the changes are done, but immediately without transition. Do you have any idea why? Thanks!

   /* CALayer*layer=[CALayer layer];
        layer.bounds =AnUIImageView.bounds;
        layer.contents=AnUIImageView.layer.contents;
        [AnotherUIImageView.layer addSublayer:layer];

        CGPoint thecentre=AnUIImageView.center;

        CALayer* layerInTarget=[AnotherUIImageView.layer.sublayers lastObject];
        [layerInTarget setPosition:[self.view convertPoint:thecentre toView:AnotherUIImageView]];
        AnUIImageView.layer.hidden=YES;

*/ // the code above works, i show it to be complete

        [CATransaction begin];
        [CATransaction setValue:[NSNumber numberWithFloat:2.0f]
                         forKey:kCATransactionAnimationDuration];
       layerInTarget.position=[self.view convertPoint:AnotherUIImageView.center toView:AnotherUIImageView];
       layerInTarget.transform=CATransform3DMakeScale(0.6,0.6,0.6);
        [CATransaction commit];

Solution

  • CALayers that are associated with a UIView (as in, they're accessed via view.layer) do not participate in implicit animations, regardless of how you configure your CATransaction. You either need to use explicit animations (using the appropriate subclass of CAAnimation) or you need to use UIView animations.