Struggle to understand the meaning, byValue CABasicAnimation, ios

I am looking into another way to create a custom indicator. Below is the incomplete code from the tutorial using CABasicAnimation to complete the task.

-(void)spin
{
    CABasicAnimation *spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    spinAnimation.toValue           = [NSNumber numberWithFloat:2*M_PI];
    spinAnimation.duration          = self.animationDuration;
    spinAnimation.delegate          = self;
    [self.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
}

      

What is toValue on line number 2 and what is it used for. When I tried to use

spinAnimation.byValue = [NSNumber numberWithFloat: 2 * M_PI];

I don't understand the idea behind these interpolation values. We search the Internet, but we cannot get the whole picture. Please help if you have any ideas on this. All comments are appreciated.

+3


source to share


1 answer


CABasicAnimations can be a little tricky to wrap your head around, but animation-related properties really aren't that hard once you can visualize what they're trying to accomplish. For example, if I have a red square that represents the layer, and I want to rotate it 360 ยฐ (as you do there), then I need to initialize the animation object, tell it what I want to animate, and where I want the animation to be passed.

The animation shown will mutate the CALayer's internal matrix so that it rotates to the specified value (in this case, 2 * M_PI

or 360หš) from the current position (since you didn't specify fromValue

) in the specified duration. The value given by the value tells the animation that, over the specified time period, the animation should interpolate (or move) by the specified value for the provided duration (for example, you can fragment the animation at 45หš "block" by specifying a byValue

of @(M_PI/2)

). The default byValue is a division of the difference toValue

and fromValue

by the duration of the animation, so the animation is smooth and continuous.



enter image description here

So, you can think of animation as from the initial rotational value , to the level of the new rotational value ,by interpolating a given amount or value over a period of time.

+3


source







All Articles