从背面退回时,对无缝循环中的图像进行无限滚动动画不起作用 [英] Animate infinite scrolling of an image in a seamless loop not working when back from back ground

查看:105
本文介绍了从背面退回时,对无缝循环中的图像进行无限滚动动画不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我有以下代码运行同一图像的无穷循环

I have the following code that run an endless loop of the same image

问题是当用户最小化应用程序时,回到它,图像停止动画,它完全消失

the problem is when the user minimize the application, and get back to it, the image stop animating and it totally disappear

这是我的代码:

-(void)cloudScroll
{
UIImage *cloudsImage = [UIImage imageNamed:@"TitleClouds.png"];
UIColor *cloudPattern = [UIColor colorWithPatternImage:cloudsImage];
CALayer *cloud = [CALayer layer];
cloud.backgroundColor = cloudPattern.CGColor;
cloud.transform = CATransform3DMakeScale(1, -1, 1);
cloud.anchorPoint = CGPointMake(0, 1);
CGSize viewSize = self.cloudsImageView.bounds.size;
cloud.frame = CGRectMake(0, 0, cloudsImage.size.width + viewSize.width, viewSize.height);
[self.cloudsImageView.layer addSublayer:cloud];

CGPoint startPoint = CGPointZero;
CGPoint endPoint = CGPointMake(-cloudsImage.size.width, 0);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSValue valueWithCGPoint:startPoint];
animation.toValue = [NSValue valueWithCGPoint:endPoint];
animation.repeatCount = HUGE_VALF;
animation.duration = 3.0;
[cloud addAnimation:animation forKey:@"position"];
}

编辑:
可能的重复项
在无缝循环中对图像进行无限滚动动画

推荐答案

查看 UIApplicationDelegate 协议参考。在方法的讨论部分,称为 applicationDidEnterBackground:,您可以找到问题的答案。

Look at UIApplicationDelegate Protocol Reference. In the discussion part of method called applicationDidEnterBackground: you can find answer on your question.

您可以尝试重新重新打开应用程序后触发动画

you can try re-firing your animation upon re-opening of the application

这篇关于从背面退回时,对无缝循环中的图像进行无限滚动动画不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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