ios - 当出现新的 View Controller 时,带有重复选项的 UIView.animate 停止

标签 ios swift animation uiview uiviewanimation

我有一个带有一个动画的 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 消失或应用程序最小化/最大化,动画将停止。这是预期的行为。

要解决此问题,您应该在 viewDidAppearapplicationDidBecomeActive 中评估是否需要动画,并在必要时调用您的 animateBallViewIn 方法。

关于ios - 当出现新的 View Controller 时,带有重复选项的 UIView.animate 停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43548375/

相关文章:

ios - React native 应用程序在启动时在设备中崩溃。在模拟器中工作正常

ios - Iphone 启动画面永远不会消失

arrays - SWIFT 解析问题

ios - 用于两指手势的自定义 UIGestureRecognizer

ios - 'JSQSystemSoundPlayer' 没有可见的@interface 声明选择器 'playSoundWithFilename:fileExtension:'

python - `save_count`参数动画matplotlib ``

javascript - D3 V4 - Canvas Transitions : d3. 计时器持续时间

ios - iTunes 错误 : not enough memory available

ios - 通过 ABAddressBookCreate 访问地址簿

jquery - 使用 css 打开和关闭动画 - 更好的动画