我看起来像一个漂亮的香草关键帧动画:
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) {
}];
不幸的是,我得到了这个输出:
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
您可以从输出中看到动画(“设置”)在添加动画(“添加”)后立即发生。似乎所有这些都应该被添加,然后所有这些都被执行,而不是以这种方式插入。
此外,duration
值 5s ,但一切都在一秒钟内完成。为什么被忽略?
我的理论是,因为属于“动画”的属性实际上并不生成隐式动画(它是视图上的属性,而不是图层,而不是标准属性),动画基本上被拒绝了系统立即继续前进。
假设是这种情况,我怎么能a)告诉系统我想要它做的是在我的视图上调用drawRect:
,这样它就可以在给定的时间呈现具有给定值的视图,或者b)告诉系统这个属性可以设置动画,然后尝试渲染我的视图吗?
或者,还有其他事情发生了吗?