gpt4 book ai didi

ios - setNavigationBarHidden 在 setViewControllers 之后不起作用

转载 作者:行者123 更新时间:2023-11-30 12:33:36 27 4
gpt4 key购买 nike

我发现 setNavigationBarHiddensetViewControllers 之后不起作用?

这是我的代码:

  • 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)

关于ios - setNavigationBarHidden 在 setViewControllers 之后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43140238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com