我模仿地呈现了一个半透明视图的viewController。这是一个自定义活动指标。我希望它覆盖视图,但保持导航栏和标签栏可见且可访问。
文档和几个SO答案(例如Presenting a Modal View Controller hides the Navigation Bar)似乎暗示将模态呈现在导航控制器上应该实现这一点。但是当我这样做时,它会正确显示标签栏,但会覆盖导航栏。
有什么想法吗?以下是相关代码:
let spinnerVC = SpinnerViewController()
spinnerVC.modalPresentationStyle = .overCurrentContext
spinnerVC.modalTransitionStyle = .crossDissolve
self.navigationController?.present(spinnerVC, animated: true, completion: nil)
//self.navigationController is definitely not nil
答案 0 :(得分:1)
您可以通过添加cell.addSubview(goalColorView)
的{{1}}来展示您的viewcontroller
,然后将其显示在当前rootViewController
上,如下所示:
navigationController
答案 1 :(得分:1)
您可以通过两种方式做到这一点: 第一个:
将此代码放在您的父视图中
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
第二个: 在警报控制器中添加对调用者的引用,以隐藏如下所示的栏:
weak var invokerView : UIViewController?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.invokerView?.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.invokerView?.navigationController?.setNavigationBarHidden(false, animated: animated)
}
答案 2 :(得分:0)
不要出席。将它作为子视图控制器添加到导航控制器的顶视图控制器,并将其视图作为子视图添加到调整框架的视图中。
let spinnerVC = SpinnerViewController()
spinnerVC.view.frame = self.navigationController?.topViewController?.view.bounds
self.navigationController?.topViewController?.addChildViewController(spinnerVC)
self.navigationController?.topViewController?.view.addSubview(spinnerVC.view)