ios - 如何在 didEnterBackground 后继续 UIImageView 动画?

标签 ios animation uiimageview calayer

我有一个简单的 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/

相关文章:

ios - 在 UITableViewCell 中进入编辑模式时隐藏 UITableViewCells(类似于联系人应用程序)

iphone - iOS:如何在 uiview 上创建破坏效果动画

iphone - 在 MultiView 应用程序上共享数据

ios - ScrollView 中的 ImageView 可快速缩放、裁剪和保存

ios - Tableview 不重新加载自定义附件类型

ios - 我如何创建一个将在 iPad 上使用弹出窗口的 segue,并推送到 iPhone 上的导航堆栈?

css - SVG 从中心重新缩放圆

ios - 如果宽度小于屏幕尺寸,UITableViewCell 将无法正确设置动画

ios - ImageView 渐变表现异常

iphone - 将视频复制到 uipasteboard