在iOS中无休止地重复滚动/动画背景吗? [英] Endless repeating scrolling/animated background in iOS?

查看:57
本文介绍了在iOS中无休止地重复滚动/动画背景吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在制作动画的2个图像上,这些图像可以在iPhone视图上无限地水平滚动.背景中不能有任何空白.如果仅用一张图像就能做到,那就太好了,但我似乎无法理解.这是我到目前为止的代码:

I'm stuck on animating 2 images that scroll on the iPhone view horizontally infinitely. The background can not have any gaps in it. If this can be done with just 1 image that would be great but I can't seem to get it. Here's the code I have so far:

-(void)moveImages {
CABasicAnimation *theAnimation; 
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=10;
theAnimation.repeatCount=100;
theAnimation.autoreverses=NO;
theAnimation.fromValue=[NSNumber numberWithFloat:320];
theAnimation.toValue=[NSNumber numberWithFloat:-320];
[theImage.layer addAnimation:theAnimation forKey:@"animateLayer"];

CABasicAnimation *theAnimation2;
theAnimation2=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation2.duration=10;
theAnimation2.repeatCount=100;
theAnimation2.autoreverses=NO;
theAnimation2.fromValue=[NSNumber numberWithFloat:640];
theAnimation2.toValue=[NSNumber numberWithFloat:-640];
[theImage2.layer addAnimation:theAnimation2 forKey:@"animateLayer2"];


}

推荐答案

好吧,在代码中,您可以创建一个新图像,这是这两个图像的组合.该合成图像的宽度为960像素,并且将第一张图像复制到最右边和最左边的位置.中间位置是第二张图片.

Well, in code you could create a new image that is the composite of these two. This composite image is 960 pixels wide, and has the first image copied to the rightmost and leftmost positions. The middle position is the second image.

您开始向左移动640像素的图像,因此您只能看到第一张图像.然后为640像素设置动画.重新启动动画时,图像始终左移640像素.

You start the image left shifted 640 pixels so you can only see the first image. Then you animate 640 pixels. When you restart the animation the image is always left shifted 640 pixels.

这样,您就可以制作一个动画.

This way you have one animation.

这篇关于在iOS中无休止地重复滚动/动画背景吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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