动画 UIView 离开屏幕然后从底部无休止地离开屏幕

Animate UIView to go up off screen then up off screen from bottom endlessly

我的问题与 this 类似。但是,我想要 swift 的更新版本,并且我希望它能无休止地运行。这是我的动画:

bubble.frame.origin = CGPoint(x: 75, y: -120)

UIView.animate(
    withDuration: 2.5,
    animations: {
        self.bubble.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height * -1.3)
    }
)

泡泡离开屏幕后,我希望它从底部重新出现,并在屏幕上不断地上升。

使用 UIViewAnimationOptions 集中的选项:

UIViewAnimationOptions.Repeat

您的代码应如下所示:

bubble.frame.origin = CGPoint(x: 75, y: -120)
UIView.animate(withDuration: 2.5, options: [UIViewAnimationOptions.Repeat], animations: {
               self.bubble.transform = CGAffineTransform(translationX: 0, y: self.view.frame.height * -1.3)
               })