UINavigationController 仅隐藏导航栏 - 后退动画问题

UINavigationController hide only navigationBar - Back animation issue(UINavigationController 仅隐藏导航栏 - 后退动画问题)
本文介绍了UINavigationController 仅隐藏导航栏 - 后退动画问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UINavigationController 中有三个 viewController.在第二个中,我需要隐藏导航栏而不是后退按钮和其他栏按钮.由于这个原因,我不能使用 isNavigationBarHidden = true
目前我正在按以下方式处理上述问题:

I have three viewControllers in a UINavigationController. In the second one I need to hide the navigation bar but not the back button and other bar button. For this reason I can't use isNavigationBarHidden = true
Currently I am handling the above as follows :

第一个视图控制器:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.barTintColor = Constants.kThemeRedColor
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.barStyle = .black
        self.navigationController?.navigationBar.isTranslucent = false
    }

第二个viewController(只隐藏导航栏):

Second viewController (hide only nav bar) :

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.view.backgroundColor = UIColor.clear
    } 

这里的问题是,当我在 firstViewController 之间导航时,在很短的时间内,当第一个 viewController 分别消失和出现时,我会看到一个黑色的导航栏.我知道这是因为用 2nd viewController 编写的代码.但我没有任何其他解决方案可以做到这一点.附上截图:

The issue here is that when I navigate from and to the firstViewController, for a very short duration when the 1st viewController is disappearing and appearing respectively, I see a black nav bar on it. I know this is because of the code written in 2nd viewController. But I don't have any other close solution of doing this. Attaching a screenshot :

第一个 viewController(应该是怎样的):

第二个视图控制器:

第一个 viewController(带有短暂的黑色导航栏):

推荐答案

First viewController中,同样设置backgroundImageshadowImagenavigationBarnil,即

In First viewController, also set the backgroundImage and shadowImage of navigationBar as nil, i.e.

class FirstVC: UIViewController
{
    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.navigationBar.setBackgroundImage(nil, for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = nil
        self.navigationController?.navigationBar.barTintColor = .red
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.barStyle = .black
    }
}

class SecondVC: UIViewController
{
    override func viewWillAppear(_ animated: Bool)
    {
        super.viewWillAppear(animated)

        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.view.backgroundColor = UIColor.clear
        self.navigationController?.navigationBar.shadowImage = UIImage()
    }
}

这篇关于UINavigationController 仅隐藏导航栏 - 后退动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)