【发布时间】:2014-06-20 19:05:56
【问题描述】:
所以我使用 Core Graphics 来旋转视图
-(void)viewDidLoad
{
[super viewDidLoad];
timer = 0.0f;
// Do any additional setup after loading the view, typically from a nib.
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(callEverySecond) userInfo:nil repeats:YES];
}
-(void)callEverySecond
{
if (timer>360) {
timer=0.0f;
[self rotateHand:timer];
}
else
{
timer++;
[self rotateHand:timer];
}
}
-(void)rotateHand:(CGFloat)angle
{
[UIView animateWithDuration:0.01 animations:^{
CGAffineTransform matrix = CGAffineTransformMakeRotation(angle*M_PI/180);
[[self.rotate layer]setAffineTransform:matrix];
}];
[[self.rotate layer]needsDisplay];
}
现在的问题是旋转速度不均匀,随机减速和加速。
这里有什么问题。
【问题讨论】:
-
使用 CoreAnimation,而不是 UIView 动画块。这就是造成问题的原因。
-
你为什么需要
timer > 360检查你是否打电话给[self rotateHand]? -
@random 我从 ios 7 中派生了这段代码,所以认为它不应该有问题
-
@VitalyS。改变提供的角度
-
您的目标只是让某物在一个圆圈内制作动画?您是否需要能够暂停/停止它?为什么你的计时器运行@0.01 秒并调用一个名为
callEverySecond的方法?
标签: ios objective-c rotation core-graphics core-animation