如何制作背景动画?
我尝试在我的应用程序中设置背景动画。
我使用带有图像的图像视图,并在视图加载时启动了一个滚动图像的计时器。
一切都好,我递减 x 并且图像似乎是动画的。
但是,当图像结束时(在我的例子中为 800px),我将 x 重置为 0,然后我看到一个丑陋的动画...
是否有更好的方法来修复这个简单的动画?
[...]
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollBackground) userInfo:nil repeats:YES];
[,,,]
int x = 0;
- (void) scrollBackground {
if (x <= -480 ) x = 0;
[background setFrame:CGRectMake(x--, background.frame.origin.y, background.frame.size.width, background.frame.size.height)];
}
谢谢
i try to animate background in my app.
I use an image view with an image and on view load I started a timer that scroll image.
It's all ok, i decrement x and the image seems to be animated.
But, when the image end (in my case 800px) i reset x to 0 and i see an ugly animation...
Is there a better way to fix this simple animation?
[...]
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(scrollBackground) userInfo:nil repeats:YES];
[,,,]
int x = 0;
- (void) scrollBackground {
if (x <= -480 ) x = 0;
[background setFrame:CGRectMake(x--, background.frame.origin.y, background.frame.size.width, background.frame.size.height)];
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“丑陋的动画”是什么意思?
如果图像以与开始类似的方式结束,那么可能没问题,在 -480 时图像应该与 x=0 时的图像相同
假设有一个圆柱体,周围有纹理,在连接点,只有当图像的结尾与同一图像的开头不同时,您才会看到差异。
what does "ugly animation" mean?
if the image ends in similar way as it begins it is probably ok, at -480 the image should be the same as at x=0
suppose to have a cilinder with a texture around it, in the point of conjunction you see the difference only if the image ends different from the begin of the same image.