iOS如何在动画期间停止状态栏消失

3

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

在动画过程中,我看到旧的ViewController上的状态栏很快向上滑动,而新的ViewController正在从上面滑下来。

有什么建议为什么会发生这种情况以及如何修复它吗?

enter image description here

由于新的ViewController没有状态栏,因此出现了这种情况:

override var prefersStatusBarHidden: Bool {
    return true
}

演示风格是

modalPresentationStyle="overCurrentContext"

新内容:

创建了一个测试XCode项目以解决此问题: https://github.com/paul301/TestSlideUp


你解决了这个问题吗? - Bruno Rodrigues de Andrade
1个回答

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最终会在状态栏消失之前出现一小段时间。如果它能够直接滑到状态栏上方就更好了。 - pflous

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接