Reputation: 12354
Imagine you have a
anime.repeatCount = Float.greatestFiniteMagnitude
and it is animating something back and fore between values ..
2 9 2 9 2 9 2 9 2 9 2 9 etc
but what you want is
2 9 3 7 3 8 1 9 3 8 1 7 etc
So - change the .fromValue
and .toValue
each time to slightly random values.
In fact, if you are changing the from and to values each time...
in fact do you have to just drop the animation and start a new one??
(So, you'd use setCompletionBlock
and do that.)
Or, can you just set it to loop forever, but, change the targets each time?? Is there a way?
Upvotes: 1
Views: 397
Reputation: 56635
The animation object is copied once it is added to the layer, so any modifications to it after that will not be propagated to the render tree. See the documentation for add(_:forKey:)
.
In other words, you can't modify an animation once it has been added to the layer. Instead you would remove it and add a new animation.
There are some "tricks" that could make it look like a series of random values — for example keyframe animations or multiple additive animations with different durations — but none of them achieve an actual animation of infinite random values.
To accomplish that you're best off adding a new animation once the previous one finishes over and over indefinitely.
Upvotes: 2