【发布时间】:2023-04-11 11:53:01
【问题描述】:
当视图加载时,我通过调用方法 animateSettings 来为 UIImageView 设置动画,该方法执行以下操作:
- (void)animateSettings {
NSLog(@"Animate Settings");
[UIView animateWithDuration:1.0f
delay:0.0f
options:(UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewKeyframeAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
self.waterImageView.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2-75);
}
completion:nil];
}
问题是当我退出应用程序并返回时,动画会冻结。我明白为什么会这样,但我似乎不知道如何恢复它。
我在 viewDidLoad 方法中设置了NSNotifications,以便在视图变为活动状态或进入后台时通知我。执行以下操作我调用animateSettings 方法或removeAnimation 方法。
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(animateSettings)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(removeAnimation)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
这是我的 removeAnimation 方法
- (void)removeAnimation {
NSLog(@"Remove Animation");
[self.waterImageView.layer removeAllAnimations];
}
问题:即使方法被正确调用(NSLogging 有效),动画仍然被冻结。
【问题讨论】:
-
进入后台时无需调用
removeAllAnimations。它是系统为您调用的。
标签: ios objective-c animation uiview uiimageview