【问题标题】:Animate UIView to go up off screen then up off screen from bottom endlessly为 UIView 设置动画以从屏幕上移出然后从底部无休止地移出屏幕
【发布时间】:2019-04-10 20:23:12
【问题描述】:

我的问题与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)
    }
)

气泡离开屏幕后,我希望它从底部重新开始,一次又一次地向上离开屏幕。

【问题讨论】:

标签: ios swift animation uiview uiviewanimation


【解决方案1】:

使用 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)
               })

【讨论】:

  • 这适用于哪个版本的 swift?我正在使用 swift 4,但这不起作用。
  • 试试options: [.Repeat]
  • @Slaknation 如果它不起作用,那意味着你做错了什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 2017-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多