3

私はいくつかの CABasicAnimations があるゲームを実装しています。たとえば、次のようにします。

CABasicAnimation * borddroit = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
borddroit.fromValue = [NSNumber numberWithFloat:0.0f];
borddroit.toValue = [NSNumber numberWithFloat:749.0f];
borddroit.duration = t;
borddroit.repeatCount = 1;
[ImageSuivante2.layer addAnimation:borddroit forKey:@"borddroit"];

この関数で一時停止します:

-(void)pauseLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
    layer.speed = 0.0;
    layer.timeOffset = pausedTime;
}

ユーザーがホームボタンを押すと、アプリケーションがバックグラウンドに入ると、アニメーションが正しく一時停止に設定されますが、アプリを再度開くと、アニメーションが消えてしまいます。

どうすれば修正できますか?

ありがとうございました

4

4 に答える 4

0

UIViewController以下のコードをクラスまたはクラスに追加するだけUIViewです。アニメーションを再開または再開する必要はありません。それはそれ自身で処理します:)

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(becomeActive:) name:UIApplicationWillEnterForegroundNotification object:nil];


-(void)becomeActive : (NSNotification*)notification
  {
    NSLog(@"app become active");
  }
于 2015-12-09T09:51:02.467 に答える
0

観察UIApplicationWillEnterForegroundNotificationして再活性化するCAAnimation

于 2015-06-26T10:36:24.537 に答える