【发布时间】:2014-03-26 11:49:22
【问题描述】:
我有一个带有背景图像的按钮,当应用程序运行时,我希望按钮旋转,当应用程序进入后台时,按钮应该停止旋转。
我调用了无限旋转按钮的方法startSpiningAnimation。
当应用程序进入后台时,我调用stopSpinningAnimation 来停止旋转动画。
- (void)startSpiningAnimation {
[self stopSpinningAnimation];
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 10.0f;
animation.repeatCount = INFINITY;
[self.button.layer addAnimation:animation forKey:@"SpinAnimation"];
}
- (void)stopSpinningAnimation {
[self.button.layer removeAllAnimations];
}
- (void)handleApplicationDidBecomeActiveNotification:(NSNotification *)not {
[self startSpiningAnimation];
}
- (void)handleApplicationWillResignActiveNotification:(NSNotification *)not {
[self stopSpinningAnimation];
}
一切都很好,我唯一的问题是每次应用程序进入前台并且动画开始时,它都是从原始位置开始的。
(我完全理解它为什么会发生,当应用程序进入后台时,我正在删除所有动画。我只是不知道如何解决这个问题)
我想要的是按钮旋转动画将从上一个角度继续。
【问题讨论】:
标签: ios iphone objective-c core-animation cabasicanimation