隐藏/显示状态栏使导航栏向下跳

问题描述

我有一个UIViewControllerCameraviewController)和一个UINavigationControllerListsNavController)。它们被嵌入到另一个视图控制器MasterViewController中,如下所示:

class MasterViewController {
    /// I also have `removeFromParent` and other cleanup,but I don't think it's relevant to my question...
    func embedCamera() { 
        self.addChild(cameraviewController)
        view.insertSubview(cameraviewController.view,at: 0)
            
        cameraviewController.view.frame = view.bounds
        cameraviewController.view.autoresizingMask = [.flexibleWidth,.flexibleHeight]
            
        cameraviewController.view.layoutIfNeeded()
    }
    func embedLists() {
        self.addChild(listsNavController)
        view.addSubview(newViewController.view)
            
        listsNavController.view.frame = view.bounds
        listsNavController.view.autoresizingMask = [.flexibleWidth,.flexibleHeight]
            
        listsNavController.view.layoutIfNeeded()
    }
}

一切正常。但是,我想在CameraviewController处于活动状态时隐藏状态栏,而在listsNavController处于活动状态时显示状态栏。我正在这样做:

enum ViewControllerType {
    case camera
    case lists
}

class MasterViewController {
    var currentViewControllerType = ViewControllerType.camera
    override var prefeRSStatusBarHidden: Bool {
        if currentViewControllerType == .camera {
            return true
        } else {
            return false
        }
    }

    func goToLists() {
        listsNavController.view.frame.origin.x = view.frame.width
        UIView.animate(withDuration: 1,animations: {
            self.listsNavController.view.frame.origin.x -= self.view.frame.width
        }) { _ in

            /// on completion,I show the status bar
            self.currentViewControllerType = .lists
            self.setNeedsstatusBarappearanceUpdate()
            
            self.listsNavController.didMove(toParent: self)
        }
    }
    func goToCamera() {
        /// I hide the status bar just before starting the animation
        self.currentViewControllerType = .camera
        self.setNeedsstatusBarappearanceUpdate()
        
        listsNavController.view.frame.origin.x = 0
        UIView.animate(withDuration: 1,animations: {
            self.listsNavController.view.frame.origin.x += self.view.frame.width
        }) { _ in
            self.cameraviewController.didMove(toParent: self)
        }
    }
}

这就是它的样子(从cameraviewControllerlistsNavController然后返回):

going from "camera View Controller" to "lists Nav Controller" and back

问题在于,当我显示状态栏时,导航栏及其下的所有内容都会向下跳转。 (为使gif保持较小,我没有显示出该条下面的内容,但是所有内容都跳了。)此外,当我返回(从listsNavControllercameraviewController)时,导航栏的标题会设置动画,但是所有内容下方仍然跳动。

是否有办法使该跳跃动画化,从而使其平滑?还是最好根本不跳(隐藏状态栏时在导航栏上方有某种“占位符”)?

先谢谢了。如果需要,我可以提供更多代码

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)