【发布时间】:2014-08-27 01:06:36
【问题描述】:
我正在移植一些看起来有点像这样的动画代码:
- (void)drawRect:(CGRect)rect
{
self.angle += 0.1;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1);
CGContextSetLineWidth(context, 2);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextAddArc(context,
self.frame.size.height/2, self.frame.size.height/2, //center
self.frame.size.height/2 - 2, //radius
0.0 + self.angle, M_PI_4 + self.angle, //arc start/finish
NO);
CGContextStrokePath(context);
}
问题是drawRect 只在第一次绘制视图时被调用一次,所以圆弧的位置永远不会更新。
怎样才能达到我想要的效果(圆弧围绕中心点缓慢连续移动)?我能找到的大多数动画示例都是执行一次性动画(例如淡入),但不是连续的。
我也尝试过类似的方法:
[arcView animateWithDuration:10.0f
delay:1.0f
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState
animations: ^(void){
_arcView.transform = CGAffineTransformMakeRotation(self.angle++);
}
completion:NULL];
显示视图时,但这似乎也没有做任何事情。
关于我的目标的更多信息:我有一个视图,我希望能够设置某些状态,例如arcView.state = STATE_READY,并为此改变它的动画方式。这是从一个 Android 项目移植过来的,在这个项目中,它就像在 View 上的 draw 方法中添加逻辑一样简单,并且最好使用一些类似的东西。
【问题讨论】:
标签: ios animation core-graphics