【发布时间】:2014-03-22 18:29:20
【问题描述】:
我正在为 iOS6 和 7 创建一个应用程序。我需要制作一个连续的背景,这意味着:我有 2 张图片要循环播放,并制作“无限”视图。我尝试了很多代码示例,但每次我的 iPhone 在打开应用程序时都会变黑。
提前致谢。
这是我目前尝试的代码:
UIImage *cloudImage = [UIImage imageNamed:@"cloud.png"];
CALayer *cloud = [CALayer layer];
cloud.contents = (id)cloudImage.CGImage;
cloud.bounds = CGRectMake(0, 0, cloudImage.size.width, cloudImage.size.height);
cloud.position = CGPointMake(self.view.bounds.size.width / 2,
cloudImage.size.height / 2);
[self.view.layer addSublayer:cloud];
CGPoint startPt = CGPointMake(self.view.bounds.size.width + cloud.bounds.size.width / 2,
cloud.position.y);
CGPoint endPt = CGPointMake(cloud.bounds.size.width / -2,
cloud.position.y);
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
anim.fromValue = [NSValue valueWithCGPoint:startPt];
anim.toValue = [NSValue valueWithCGPoint:endPt];
anim.repeatCount = HUGE_VALF;
anim.duration = 8.0;
[cloud addAnimation:anim forKey:@"position"];
但我需要在无限循环中有 2 张照片。并且该背景图像正在向上滚动而不是横向滚动
【问题讨论】:
-
你能分享一下你目前尝试过的代码吗?
-
我刚刚将代码添加到我的问题中