所以我是新来的斯威夫特,我正试图做一个汽车游戏,其中有一个球员的汽车和对手的汽车。对手的赛车将通过屏幕并重复,直到游戏结束。我现在正在执行对手的赛车,但我有一个问题,在这个问题上,对手汽车的动画只运行在屏幕的一半,直到他们消失,并再次启动循环。我如何改变这一点,以便对手的汽车通过整个屏幕?下面是我对对手汽车的当前代码:
//animation of opponent car1
UIView.animate(withDuration: 4, delay: 0.0, options: [UIViewAnimationOptions.repeat], animations:
{
self.car1image.center.y += self.view.bounds.width
}, completion: nil
)
//opponent car2
UIView.animate(withDuration: 4, delay: 1.0, options: [UIViewAnimationOptions.repeat], animations:
{
self.car2image.center.y += self.view.bounds.width
}, completion: nil
)
//opponent car3
UIView.animate(withDuration: 4, delay: 2.0, options: [UIViewAnimationOptions.repeat], animations:
{
self.car3image.center.y += self.view.bounds.width
}, completion: nil
)发布于 2018-04-04 15:53:23
您正在将视图width添加到y位置。您应该添加视图。(实际上,您可能应该添加屏幕高度,而不是视图高度。)
计算汽车图像视图和屏幕底部之间的距离,而不是增加视图/屏幕的高度,这样做会更好,因为增加全屏高度会使图像视图超过屏幕底部,除非从屏幕顶部开始居中。
https://stackoverflow.com/questions/49655390
复制相似问题