为 UIView 设置动画以从屏幕上移出然后从底部无休止地移出屏幕
Posted
技术标签:
【中文标题】为 UIView 设置动画以从屏幕上移出然后从底部无休止地移出屏幕【英文标题】:Animate UIView to go up off screen then up off screen from bottom endlessly 【发布时间】: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)
)
气泡离开屏幕后,我希望它从底部重新开始,一次又一次地向上离开屏幕。
【问题讨论】:
developer.apple.com/documentation/uikit/uiview/1622451-animate 【参考方案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 如果它不起作用,那意味着你做错了什么以上是关于为 UIView 设置动画以从屏幕上移出然后从底部无休止地移出屏幕的主要内容,如果未能解决你的问题,请参考以下文章