iOS 6 - 从后台返回应用程序后恢复动画

时间:2013-07-22 18:18:33

标签: ios animation ios6 multitasking

我有一个应用程序,在下载开始时开始旋转UIImageView。动画工作正常,直到我进入后台,我似乎无法重新启动动画。我正在使用UINotificationCenter,我已经订阅了UIApplicationDidEnterBackgroundNotification和UIApplicationWillEnterForegroundNotification。我尝试过使用Technical Q&A QA1673,但那些似乎没有做任何事情。我的背景和前景通知方法如下所示:

    - (void)didEnterBackground:(NSNotification *)notification
{
//    NSArray *animationKeys = [_downloadSpinnerImageView.layer animationKeys];
//    animationWithPosition = [[_downloadSpinnerImageView.layer animationForKey:@"transform"] copy];
//    [self pauseLayer:_downloadSpinnerImageView.layer];

    [_downloadSpinnerImageView.layer removeAllAnimations];
}

- (void)willEnterForeground:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:YES];
//
//    if(animationWithPosition != nil)
//    {
//        [_downloadSpinnerImageView.layer addAnimation:animationWithPosition forKey:@"transform"];
//        animationWithPosition = nil;
//    }
//    
//    [self resumeLayer:_downloadSpinnerImageView.layer];
//    [self refreshDownloadStatusView];

    [self refreshDownloadStatusView];
}

我正在使用以下方式启动动画:

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 10;
fullRotation.repeatCount = HUGE_VALF;
fullRotation.removedOnCompletion = NO;
[_downloadSpinnerImageView.layer addAnimation:fullRotation forKey:@"360"];

很抱歉,如果这看似重复,但我发现的其他一切都与从最后一个位置恢复动画而不是重新开始动画有关。我甚至无法重新开始。

0 个答案:

没有答案