我有一个带有一个动画的 View Controller ,该动画设置为使用选项无限循环:[.autoreverse, .repeat]
- 然而,当我呈现一个新的 View Controller (设置 VC) - 然后关闭它以返回带有动画的 View ,动画不是动画。 View (ballContainer
) 只是保持静态,而它应该仍然是动画的。
animateBallViewIn 方法
func animateBallViewIn() {
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.5, animations: {
self.ballContainer.alpha = 1.0
}) { (true) in
UIView.animate(withDuration: 0.5, delay: 0.0, options: [.autoreverse, .repeat], animations: {
ballViewBottomConstraint = 20.0
self.view.layoutIfNeeded()
}, completion: nil)
}
}
注意 - 我在属性观察器中调用 animateBallViewIn()
。
在显示另一个 View Controller 返回到上面的动画后,我如何保持它的动画效果?
最佳答案
如果 View 消失或应用程序最小化/最大化,动画将停止。这是预期的行为。
要解决此问题,您应该在 viewDidAppear
和 applicationDidBecomeActive
中评估是否需要动画,并在必要时调用您的 animateBallViewIn
方法。
关于ios - 当出现新的 View Controller 时,带有重复选项的 UIView.animate 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43548375/