I have a CALayer and I would like to use it as an UIImageView. That way I’ll be able to move it with timers etc… so here the layer :
CALayer *rootLayer = [CALayer layer];
And I would like to move it with timer like that :
Image.center=CGPointMake(Image.center.x +10, Image.center.y );
For this you’ll need a
CABasicAnimation. For the timer, create anNSTimer. Make sure that the timer fires the method on the main thread using one of theperformSelectorOnMainThreadmethods.That method will add the
CABasicAnimationto the layer. You’ll have to be careful with the end positions as when the animation finishes, your layer will still be visible in it’s original position.To resolve that you’ll need to update the model value of the layer in the
animationDidStartdelegate callback of theCABasicAnimation.Note that if it’s a repeating animation – which I guess it is given you’re using a timer – you can use the
removedOnCompletionflag. That means you can re-use the same animation repeatedly. Check out this question for details on how to make use of that:How to reuse an CABasicAnimation when not removed after completion?