Need help with animations on iPhone

I am working on an animated clock application for the iPhone, and I have to rotate all 3 nodes in the view that I received in the following code:

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

clockarm.layer.anchorPoint = CGPointMake(0.0, 0.0);
[CATransaction commit];

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
[CATransaction setValue:[NSNumber numberWithFloat:50.0] forKey:kCATransactionAnimationDuration];

CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:-60.0];
animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
animation.delegate = self;
[clockarm.layer addAnimation:animation forKey:@"rotationAnimation"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];


[CATransaction commit];

The problem that it only rotates once, i.e. just 360 degrees and then stops. I want to multiply needles endlessly. How can I do it?

+3
source share
6 answers

I have never done this, but that’s what I would try. You have already set the delegate to self. Insert the delegate method animationDidStop:finished:and just call the method in which you put the code above. Be sure to call it in the main thread (using performOnMainThread).

+4

, , , , . , CAKeyframeAnimation .

, . . , - .

+4

animationDidFinish . CA 360 .

+3

. , 50 , , . , , , .

P.S. fromValue , .

+1

"scalingAnimation.repeatCount = 1000000000;" . , .

0

n no. -1, , u.

0

Source: https://habr.com/ru/post/1703223/


All Articles