我的动画代码被执行(我可以使用任何动画行上的断点停止执行(,但我在视觉上什么也看不到。它甚至需要我为无所事事的持续时间设置的一秒钟,它只是执行下一个 segue。我的文本字段应该在 1 秒内淡出。
//animate text fields (fade till dissappear)
let animationTextFields = {() -> Void in
self.firstField.alpha = 0.0
self.secondField.alpha = 0.0
self.thirdField.alpha = 0.0
self.fourthField.alpha = 0.0
}
UIView.animate(withDuration: 1.0, animations: animationTextFields)
//animate next button (flies right)
//animate back button (flies left)
//animate "please" label (flies up)
self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)
如您所见,我还需要进一步的动画,但一次一个步骤。
知道为什么我的动画没有发生吗?
在动画完成后放置 segue。
UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: animationTextFields, completion: { (finished: Bool) in
self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)
})
如果您希望它们同时发生,您可以通过以下transitionCoordinator
协调动画与过渡:
performSegue(withIdentifier: "SegueIdentifier", sender: self)
transitionCoordinator?.animate(alongsideTransition: { context in
UIView.animate(withDuration: 1) {
self.label.alpha = 0 // fade out
}
}, completion: { context in
self.label.alpha = 1 // if you want, when done, make it visible again so when you return back here you can see it
})
尝试在
闭包animationTextFields
内编写self.layoutIfNeeded()
。
试试这段代码
UIView.animate(withDuration: 0.3)
{
self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)
}