1

我有一个应用程序在下载开始时开始旋转 UIImageView。动画效果很好,直到我进入后台并且我似乎无法重新启动动画。我正在使用 UINotificationCenter,并且我已经订阅了 UIApplicationDidEnterBackgroundNotification 和 UIApplicationWillEnterForegroundNotification。我曾尝试使用技术问答 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"];

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

4

0 回答 0