切换应用程序时删除了图层动画 [英] Layer animations removed when switching apps

查看:84
本文介绍了切换应用程序时删除了图层动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(iOS 5.0)

我将CAKeyframeAnimation添加到视图的图层中,该图层具有无限重复计数(光标闪烁)。但是,当切换应用程序并返回时,动画会从图层中删除(或者可能是整个图层都被替换了,我不确定)。

I have an CAKeyframeAnimation added to a view's layer with an infinite repeat count (a cursor blinking). However, when switching apps and coming back, the animation gets removed from the layer (or possibly the entire layer is replaced, I'm not sure).

我尝试重新-将它们添加到viewDidLoad和viewWillAppear上,但在切换应用程序时都不会调用它们。我确实发现UIApplicationDelegate中有一个applicationWillEnterForeground:方法。我打算使用此功能,但我有两个问题:

I tried re-adding them on viewDidLoad and viewWillAppear, but neither is called when switching apps. I did find there is a applicationWillEnterForeground: method in UIApplicationDelegate. I'm planning to use this but I have two questions:


  • 是否还有其他情况会触发动画或图层的卸载?有没有更合适的事件可以听?

  • (从设计模式的角度)响应这些事件(例如使用目标动作)的最佳实践是什么?

推荐答案

切换应用程序或视图控制器时,系统将停止图层上的动画(完成),因此您可以将 removedOnCompletion 设置为 NO (默认值为 YES ),它将起作用。

When switching apps or view controllers, the system will let the animations on the layer stop (complete), so you can set removedOnCompletion to NO (the default is YES), and it will work.

这篇关于切换应用程序时删除了图层动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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