繁体   English   中英

setNavigationBarHidden在setViewControllers之后不起作用

[英]setNavigationBarHidden doesn't work after setViewControllers

我发现setNavigationBarHiddensetViewControllers之后setViewControllers

这是我的代码:

  • HomeNavController.swift

     class HomeNavController: UINavigationController { weak var tabBar: HomeTabBar! var tab: HomeTab = .match { didSet { switch self.tab { case .match: self.setViewControllers([MatchViewController()], animated: false) case .moments: self.setViewControllers([MomentsViewController()], animated: false) case .myPosts: self.setViewControllers([PostsViewController()], animated: false) } } } } 
  • MatchViewController.swift

     override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: false) } 

当我第一次切换到MatchViewController实例时,它运行良好,但是用func setViewControllers更改了HomeNavController实例的viewControllers后,它不起作用。

这是UINavigationController的错误吗?

也许尝试设置属性,这在我的情况下有效:

    let navigationBarAppearance = UINavigationBar.appearance()
    let transparentColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0);
    // Sets the translucent background color
    navigationBarAppearance.backgroundColor = transparentColor
    navigationBarAppearance.titleTextAttributes = [NSForegroundColorAttributeName:transparentColor]
    // Hides the border
    navigationBarAppearance.shadowImage = UIImage()
    navigationBarAppearance.setBackgroundImage(UIImage(), for: .default)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM