Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CABasicAnimation change duration/speed during rotation

I am using CABasicAnimation to rotate forever an imageView and I want to change rotation speed during rotation. Can anybody help me with this? Thanks in advance!

like image 710
leon4ic Avatar asked Oct 04 '11 17:10

leon4ic


2 Answers

You can see https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW2

And I use this code.

Objective-C

self.layer.timeOffset = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil]; 
self.layer.beginTime = CACurrentMediaTime(); 
self.layer.speed= theSpeedYouWant;

Swift

self.layer.timeOffset = self.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
self.layer.beginTime = CACurrentMediaTime();
self.layer.speed = speed;
like image 98
Yu-Lin Wang Avatar answered Oct 20 '22 06:10

Yu-Lin Wang


You can start a new basic animation with different speed and take as the start value the one you receive from the presentation layer.

like image 45
Bernd Rabe Avatar answered Oct 20 '22 04:10

Bernd Rabe