【问题标题】:Endless repeating scrolling/animated background in iOS?iOS中无休止的重复滚动/动画背景?
【发布时间】:2012-08-18 01:07:22
【问题描述】:

我一直在为 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"];


}

【问题讨论】:

    标签: iphone objective-c ios cabasicanimation


    【解决方案1】:

    嗯,在代码中,您可以创建一个由这两者组合而成的新图像。此合成图像宽 960 像素,将第一张图像复制到最右边和最左边的位置。中间位置是第二张图片。

    您将图像左移 640 像素,因此您只能看到第一张图像。然后为 640 像素设置动画。当您重新启动动画时,图像总是左移 640 像素。

    这样你就有了一个动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多