Animate infinite scrolling of an image in a seamless loop not working when back from back ground [duplicate]

天大地大妈咪最大 提交于 2019-12-25 01:53:58

问题


Possible Duplicate:
Animate infinite scrolling of an image in a seamless loop

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

Here is my code:

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

EDIT: possible duplicate of Animate infinite scrolling of an image in a seamless loop


回答1:


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



来源:https://stackoverflow.com/questions/13233664/animate-infinite-scrolling-of-an-image-in-a-seamless-loop-not-working-when-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!