按下主页按钮时,CABasicAnimation消失 [英] CABasicAnimation disappear when home button is pushed

查看:139
本文介绍了按下主页按钮时,CABasicAnimation消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个游戏,其中有一些CABasicAnimations. 例如,像这样:

I'm implementing a game, in which i have some CABasicAnimations. For example, like this :

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"];

我通过此功能将其暂停:

I put it in pause with this function :

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

当我的应用程序进入背景时,由于用户按下主屏幕按钮,动画正确设置为暂停,但是当我重新打开我的应用程序时,动画消失了.

When my application is entering background, because the user push the home button, the animations correctly set in pause, but when i re-open my app, the animations have disappeard.

请问我该如何解决?

谢谢

推荐答案

这是正确的内置行为.当您离开应用程序时,所有动画将从其图层中删除:系统在每个图层上调用removeAllAnimations.

This is correct and built-in behavior. When you leave the app, all animations are removed from their layers: the system calls removeAllAnimations on every layer.

通常,这并不重要,原因如下:假设您为从A点到B点的球设置了动画,并且当用户离开您的应用程序时,该动画在动画中指向B点的一半.当用户回来时,动画消失了,但是球在 点B处,因此应用程序可以继续.发生的一切就是我们跳过了一些动画部分.

This doesn't matter, usually, for the following reason: suppose you animate a ball from point A to point B and it is halfway to point B in the animation when the user switches away from your app. When the user comes back, the animation is gone, but the ball is at point B, so the app can just continue. All that happens is that we've skipped some of the animation part.

这篇关于按下主页按钮时,CABasicAnimation消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆