gpt4 book ai didi

iphone - iOS 中无休止的重复滚动/动画背景?

转载 作者:行者123 更新时间:2023-11-29 13:30:32 24 4
gpt4 key购买 nike

我一直在为 2 个在 iPhone View 上无限水平滚动的图像制作动画。背景不能有任何空隙。如果只用一张图片就可以做到这一点,那就太好了,但我似乎无法理解。这是我到目前为止的代码:

-(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 像素宽,并将第一张图像复制到最右侧和最左侧的位置。中间位置是第二张图片。

您开始将图像左移 640 像素,因此您只能看到第一张图像。然后你为 640 像素制作动画。重新启动动画时,图像始终向左移动 640 像素。

这样你就有了一个动画。

关于iphone - iOS 中无休止的重复滚动/动画背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12014975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com