Reputation: 257
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 );
Upvotes: 1
Views: 550
Reputation: 26652
For this you'll need a CABasicAnimation
. For the timer, create an NSTimer
. Make sure that the timer fires the method on the main thread using one of the performSelectorOnMainThread
methods.
That method will add the CABasicAnimation
to 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 animationDidStart
delegate callback of the CABasicAnimation
.
Note that if it's a repeating animation - which I guess it is given you're using a timer - you can use the removedOnCompletion
flag. 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?
Upvotes: 1