-->

在IOS无尽重复滚动/动画背景?(Endless repeating scrolling/anima

2019-10-17 03:59发布

我卡上的动画2幅图像能够在iPhone上查看水平滚动无限。 背景不能有任何空隙。 如果这可以只用1图像来完成,这将是伟大的,但我似乎无法得到它。 这里是我到目前为止的代码:

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


}

Answer 1:

那么,在代码中你可以创建一个新的形象,是这两者的组合。 这个合成图像为960个像素宽,并且具有复制到最右边和最左边的位置上的第一个图像。 中间位置是所述第二图像。

你开始离开图像换成640个像素,所以你只能看到第一张图像。 然后你动画640个像素。 当您重新启动动画的图像始终向左移动640个像素。

这样,你有一个动画。



文章来源: Endless repeating scrolling/animated background in iOS?