【发布时间】:2018-07-09 15:45:33
【问题描述】:
我的应用程序中有多个视图控制器。我想在我的第一个视图控制器中隐藏navigationbar。所以我使用下面的代码来隐藏导航栏
navigationController?.setNavigationBarHidden(navigationController?.navigationBarHidden == false, animated: true);
现在我想在其他视图控制器中添加导航栏,但是我的导航栏在该视图控制器中不可见。为什么会这样?
我的故事板显示导航栏,但一旦我尝试运行我的应用程序,它就消失了。
如果我从一个视图控制器中隐藏导航栏,那么我们就不能使用导航控制器,是这样吗?我希望我错了。那么导航栏不显示是什么原因呢?
编辑:
我还希望我的视图控制器只处于纵向模式。所以我做了以下是导致问题的原因吗?
extension UINavigationController{
public override func shouldAutorotate() -> Bool {
if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft ||
UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight ||
UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {
return false
}
else {
return true
}
}
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return [UIInterfaceOrientationMask.Portrait ,UIInterfaceOrientationMask.PortraitUpsideDown]
}
}
编辑 1:
我正在使用以下代码从一个视图控制器移动,而不是从情节提要链接。现在是这个问题吗?
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondViewController = storyboard.instantiateViewControllerWithIdentifier("HomeVC")
presentViewController(secondViewController, animated: false, completion: nil)
编辑 2:
请查看我的以下屏幕截图。我对 secondview 控制器的设置是什么
编辑 3:
【问题讨论】:
-
您在整个导航控制器堆栈上进行设置,因此它不会在放置在导航控制器上的视图控制器上可见。如果您只需要在某些视图控制器上禁用,只需执行 [self.navigationController setNavigationBarHidden:YES];在视图控制器的 viewDidLoad 方法中
标签: ios swift uinavigationcontroller