【问题标题】:Animate infinite scrolling of an image in a seamless loop not working when back from back ground [duplicate]从背景返回时,在无缝循环中动画无限滚动图像不起作用[重复]
【发布时间】:2023-07-09 12:03:01
【问题描述】:

可能重复:
Animate infinite scrolling of an image in a seamless loop

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

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

这是我的代码:

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

编辑: Animate infinite scrolling of an image in a seamless loop的可能重复

【问题讨论】:

  • 我已更新我对该问题的回答以解决您的问题。

标签: iphone objective-c xcode calayer cabasicanimation


【解决方案1】:

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

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

【讨论】:

  • 有没有人有一个示例项目 zip 可以在其中运行和工作?我的测试没有错误,但我从未看到任何图像在我的视图中滚动。谢谢。
最近更新 更多