我发现setNavigationBarHidden
之后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 HomeNavController
更改setViewControllers
实例的viewControllers之后,它不起作用。< / p>
是UINavigationController
的错误吗?
答案 0 :(得分:0)
也许尝试设置属性,这在我的情况下起作用:
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)