I have a array of CALayers that i’m looping and trying to move.
Tile is a CALayer subclass and has a CGRect property named originalFrame where i store the frame i want to animate to.
When i’m useing the code below everything is instant moved to the correct possition and there is no 4 sec animation. How can i animate these CALayer?
for (int i = 0; i < [tileArray count]; i++) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelay:i];
[UIView setAnimationDuration:4];
Tile *currentCard = (Tile*)[tileArray objectAtIndex:i];
currentCard.frame = currentCard.originalFrame;
[UIView commitAnimations];
}
You have two problems: the first is that you’re trying to animate the layer’s
framedirectly. Since this is a derived property, you can’t do that. Instead, you have to animate thepositionproperty. http://developer.apple.com/library/mac/#qa/qa1620/_index.htmlSecond, you’re using UIView’s
+beginAnimationsAPI, but you say your Tile objects are CALayers, not UIViews. So you don’t need to use+beginAnimations. Instead you need to use a CAAnimation object, like CABasicAnimation (untested):