xcode 动画无限滚动的图像在一个无缝循环不工作时,从背景[复制]

q8l4jmvw  于 2023-02-09  发布在  其他
关注(0)|答案(1)|浏览(106)
    • 此问题在此处已有答案**:

Animate infinite scrolling of an image in a seamless loop(3个答案)
昨天关门了。
我有下面的代码运行同一图像的无限循环
问题是当用户最小化应用程序,并返回到它,图像停止动画,它完全消失
下面是我的代码:

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

kxkpmulp1#

查看UIApplicationDelegate协议参考。在名为applicationDidEnterBackground:的方法的讨论部分,您可以找到问题的答案。
你可以尝试在重新打开应用程序时重新启动动画

相关问题