【问题标题】:iOS stop status bar from disappearing during animationiOS停止状态栏在动画期间消失
【发布时间】:2017-06-17 09:28:57
【问题描述】:

我正在从带有状态栏的 ViewController 切换到没有状态栏的 ViewController。

在动画过程中,当新的 ViewController 在顶部滑动时,我看到状态栏在旧 ViewController 上快速向上滑动。

有什么建议为什么会发生这种情况以及如何解决这个问题?

新的 ViewController 没有状态栏,原因是:

override var prefersStatusBarHidden: Bool {
    return true
}

演示风格是

modalPresentationStyle="overCurrentContext"

新:

创建了一个带有问题的测试 XCode 项目: https://github.com/paul301/TestSlideUp

【问题讨论】:

  • 你有解决这个问题的办法吗?

标签: ios swift uistoryboard uistoryboardsegue


【解决方案1】:

要使新的 ViewController 停留在旧状态栏的顶部,您需要创建一个新的 UIWindow 并手动执行动画。
示例代码:

var window = UIWindow()

//to show new view controller
func showWindow() {
    let vc = NewViewController()
    self.window.rootViewController = vc
    self.window.backgroundColor = UIColor.clear
    self.window.windowLevel = UIWindowLevelStatusBar
    self.window.frame = CGRect(x: 0, y: UIScreen.main.bounds.height, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
    self.window.isHidden = false

    UIView.animate(withDuration: 0.5) { 
        self.window.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
    }
}

【讨论】:

  • 这看起来比以前好多了,但现在新的 ViewController 最终会在消失之前有一瞬间的状态栏。要是能滑到状态栏上面就好了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 2020-01-21
  • 2014-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多