【发布时间】:2021-07-08 03:35:03
【问题描述】:
我希望我的 swift 代码遵循我创建的 gif。发生的事情是在第一个动画之后没有任何位置变化。就像我创建的 gif 一样,它应该先向下移动,然后再向上移动。我尝试乘以负数 -0.15,认为它会朝北。现在没有效果。
UIView.animate(withDuration: 1, animations: {
self.block1.frame = CGRect(x: 0, y: self.view.frame.height * 0.15, width: self.view.frame.width, height: self.view.frame.height * 0.1)
self.block1.center = self.view.center
}) { done in
/// first animation finished, start second
if done {
UIView.animate(withDuration: 1, animations: {
self.block1.frame = CGRect(x: 0, y: self.view.frame.height * (-0.15), width: self.view.frame.width, height: self.view.frame.height * 0.1)
self.block1.center = self.view.center
})
}
}
【问题讨论】:
-
首先从动画循环中删除
self.block1.center = self.view.center- 它正在与其他属性竞争
标签: swift animation position completion chained