What am I missing from this implicit animation code for CALayer?
I am trying to get the following code from a book to work. It animates the layer of a UIImageView called the Chicken :
[CATransaction setValue:kCAMediaTimingFunctionEaseInEaseOut forKey:kCATransactionAnimationTimingFunction];
[CATransaction setValue:[NSNumber numberWithFloat:1.0] forKey:kCATransactionAnimationDuration];
theChicken.position = CGPointMake(225, 144);
The problem is that this code does not animate. It just moves the chicken to 225,144 with no animation at all (it just teleports there like magic). Can anyone help me correct the code so it works ?
Thanks in advance开发者_JAVA技巧,
Martin
What happens if you wrap it in:
[CATransaction begin];
[CATransaction setValue:kCAMediaTimingFunctionEaseInEaseOut forKey:kCATransactionAnimationTimingFunction];
[CATransaction setAnimationDuration:1.0];
theChicken.position = CGPointMake(225, 144);
[CATransaction commit];
If it still doesn't work it could be to do with the layer delegate. Is this layer a sub-layer? I think the delegate is set to nil on root layers which would have this affect.
You can use a UIView animation instead:
[UIView beginAnimations:@"anim1" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
theChicken.position = CGPointMake(225, 144);
[UIView commitAnimations];
精彩评论