I have what looks to me like a pretty vanilla key-frame animation:
NSTimeInterval duration = 5.;
[UIView animateKeyframesWithDuration:duration delay:0 options:0 animations:^{
CGFloat intervals = 25.;
for ( NSUInteger i = 0; i < intervals; i++) {
CGFloat start = 1./intervals*i;
CGFloat last = 1./intervals;
NSLog(@"adding @ %f for %f", start, last);
[UIView addKeyframeWithRelativeStartTime:start relativeDuration:last animations:^{
CGFloat width = 12./intervals*(i+1);
NSLog(@"setting to %f", width);
self.colorWheel.lineWidth = width;
}];
}
} completion:^(BOOL finished) {
}];
Unfortunately, I get this output:
2014-02-01 22:43:18.653 [26175:60b] adding @ 0.000000 for 0.040000
2014-02-01 22:43:18.655 [26175:60b] setting to 0.480000
2014-02-01 22:43:18.657 [26175:60b] adding @ 0.040000 for 0.040000
2014-02-01 22:43:18.658 [26175:60b] setting to 0.960000
2014-02-01 22:43:18.660 [26175:60b] adding @ 0.080000 for 0.040000
2014-02-01 22:43:18.661 [26175:60b] setting to 1.440000
2014-02-01 22:43:18.663 [26175:60b] adding @ 0.120000 for 0.040000
2014-02-01 22:43:18.665 [26175:60b] setting to 1.920000
2014-02-01 22:43:18.667 [26175:60b] adding @ 0.160000 for 0.040000
2014-02-01 22:43:18.668 [26175:60b] setting to 2.400000
2014-02-01 22:43:18.669 [26175:60b] adding @ 0.200000 for 0.040000
2014-02-01 22:43:18.671 [26175:60b] setting to 2.880000
...
2014-02-01 22:43:18.725 [26175:60b] adding @ 0.800000 for 0.040000
2014-02-01 22:43:18.727 [26175:60b] setting to 10.080000
2014-02-01 22:43:18.728 [26175:60b] adding @ 0.840000 for 0.040000
2014-02-01 22:43:18.728 [26175:60b] setting to 10.560000
2014-02-01 22:43:18.729 [26175:60b] adding @ 0.880000 for 0.040000
2014-02-01 22:43:18.730 [26175:60b] setting to 11.040000
2014-02-01 22:43:18.731 [26175:60b] adding @ 0.920000 for 0.040000
2014-02-01 22:43:18.732 [26175:60b] setting to 11.520000
2014-02-01 22:43:18.733 [26175:60b] adding @ 0.960000 for 0.040000
2014-02-01 22:43:18.734 [26175:60b] setting to 12.000000
What you can see from the output is that the animation ("setting") is happening right after the adding of the animation ("adding"). It seems that all of these should be added, then all of them executed, rather than interleafed this way.
Furthermore, the duration
value is 5s, yet everything is finishing in a second. Why is it being ignored?
My theory is that because the property being "animated" does not actually generate an implicit animation (it's a property on the view, not the layer, and not a standard property at that), the animation is basically in effect rejected and the system moves on immediately.
Assuming this is the case, how can I a) tell the system that what I want it to do is call drawRect:
on my view so it can render the view with the given value at the given time, or b) tell the system this property can be animated and have it then try to render my view anyway?
Or, is something else going on?