Note that there are some explanatory texts on larger screens.

plurals
  1. POCABasicAnimation - Animating between two angles
    primarykey
    data
    text
    <p>I'm attempting to create an animated <code>CALayer</code> that uses a <code>CABasicAnimation</code> in order to animate an object that rotates at discrete intervals between two angles. Note the word discrete: I'm not trying to create a continuous animation between two points, but rather I want to calculate fixed increments between each angle in order to create a discrete movement feel.</p> <p>Here's a diagram:</p> <p><img src="https://i.stack.imgur.com/utKAr.png" alt="enter image description here"></p> <p>I've looked into setting the <code>byValue</code> attribute of the <code>CABasicAnimation</code>, but I can't seem to get it to work since you can't use <code>fromValue</code>, <code>ToValue</code>, and <code>byValue</code> in one animation. <code>fromValue</code> is always from zero, so I guess that could be dropped, but it still never animates correctly when using the current <code>endAngle</code> as the <code>toValue</code> and a <code>byValue</code> of <code>0.1</code> (arbitrarily chosen but should work for testing). Any ideas on how to implement this? Here's code I'm using:</p> <pre><code>anim = [CABasicAnimation animationWithKeyPath:@"currentEndAngle"]; anim.duration = 0.5f; anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; anim.toValue = [NSNumber numberWithFloat:self.endAngle]; anim.byValue = [NSNumber numberWithFloat:0.1f]; anim.repeatCount = HUGE_VALF; [anim setDelegate:self]; [self addAnimation:anim forKey:@"animKey"]; </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload