我動畫一個UIImageView上下時通過調用其執行以下操作方法animateSettings認爲負載:問題恢復UIVIEW動畫:ios7?
- (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'。它是由系統調用的。 – matt