gpt4 book ai didi

swift - 如果应用程序转到后台,UIView 动画将不起作用

转载 作者:行者123 更新时间:2023-11-30 10:01:46 26 4
gpt4 key购买 nike

我有一个小问题游戏,如果用户回答时间太长,就会超时并自动触发到特定屏幕的自定义转场。

    let firstClassView = self.sourceViewController.view
let secondClassView = self.destinationViewController.view
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
firstClassView.clipsToBounds = true
secondClassView.clipsToBounds = true
let secondClassFrame = CGRect(x: screenWidth, y: 0, width: screenWidth, height: screenHeight)
secondClassView.frame = secondClassFrame
guard let window = UIApplication.sharedApplication().keyWindow else {
return
}
window.insertSubview(secondClassView, aboveSubview: firstClassView)
if let questionVC = self.destinationViewController as? QuestionResultViewController {
questionVC.prepareResultView()
}
UIView.animateWithDuration(0.4, animations: { () -> Void in
firstClassView.frame = CGRectOffset(firstClassView.frame, -screenWidth, 0)
secondClassView.frame = CGRectOffset(secondClassView.frame, -screenWidth, 0)
}) {_ -> Void in
self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil)
}

此代码和转场工作正常,除非用户在转场之前将应用程序发送到后台(并再次打开它)。在这种情况下,到达了 UIView.animate block ,但它的内容似乎永远不会被调用,因此没有动画播放! (我在那里有一个打印命令,但它没有被触发)

如果我的描述令人困惑:

案例1:

  • 用户到达问题屏幕

  • 问题的计时器超时

  • Segue 触发器

  • 动画 block 已到达并完美播放

案例2:

  • 用户到达问题屏幕

  • 将应用发送到后台

  • 再次打开应用

  • 问题的计时器超时

  • Segue 触发器

  • 到达动画 block ,但没有任何反应 -> ???

为什么会发生这种情况?我尝试使用layoutIfNeeded及其变体,但没有任何效果。动画 block 的内容永远不会被调用。根据我使用断点的测试,应用程序在到达 UIView 行之前完全停止(并在大约 10 秒后崩溃)。

最佳答案

事实证明它与 UIView block 无关。我有一个自定义 UILabel 类,它的layoutSubviews 方法在应用程序进入后台后进入不可检测的无限循环。

抱歉造成困惑。

关于swift - 如果应用程序转到后台,UIView 动画将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38129873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com