我有一个简单的 UIImageView (myimageview
) 加载了一个 NSArray(animationArray
) 动画图像(在我的 ViewController.m 中)
:
[self.myimageview setAnimationImages:self.animationArray];
[self.myimageview setAnimationDuration:[self durationTime]];
[self.myimageview setAnimationRepeatCount: 1];
[self.myimageview startAnimating];
我知道在哪里使用 stopAnimating 等。但是我有一个奇怪的问题。当屏幕锁定时,我的动画没有任何反应。任何东西都像魅力一样。它在我解锁屏幕后继续。
但是,当我的应用进入后台模式时,整个动画就会停止(我的动画有 2-3 分钟长,因此这是 Not Acceptable )。我搜索了一下,发现了这个主题:
How to pause a UIImageView animation
它说使用此代码的地方:
UIView *viewBeingAnimated = //your view that is being animated
viewBeingAnimated.frame = [[viewBeingAnimated.layer presentationLayer] frame];
[viewBeingAnimated.layer removeAllAnimations];
//when user unpauses, create new animation from current position.
现在我正尝试在 AppDelegate.m 中的代码中实现这一点
// in -(void)applicationDidEnterBackground:
self.viewController.myimageview.frame = [[self.myimageview.frenchPress.layer presentationLayer] frame];
但是我在 XCode 中遇到了这个问题(对于上面的行),我无法继续:
AppDelegate.m:40:47: Receiver type 'CALayer' for instance message is a forward declaration
如果我退出到后台值:self.currentDate
(仅供旁注,以备不时之需),我会节省时间。
如何不间断地暂停和播放动画?
最佳答案
为了访问 CALayer
的所有消息和属性,您必须包含其相应的框架 header :
#import <QuartzCore/QuartzCore.h>
这有望消除警告。
关于ios - 如何在 didEnterBackground 后继续 UIImageView 动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288221/