我已经创建了一个两屏的iPhone应用程序.之后,用户被带到第一个视图.我添加了一个UINavigationController.它工作得非常好.

如何仅删除打开视图的导航栏?

MainWindow

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


self.splashScreen = [[SplashScreen alloc] 
                initWithNibName:@"SplashScreen" 
                bundle:nil];
if (self.pageController == nil) {
openingpage *page=[[openingpage alloc]initWithNibName:@"openingpage" bundle:[NSBundle mainBundle]];
    self.pageController = page;
    [page release];
}
[self.navigationController pushViewController:self.pageController animated:YES];

[window addSubview:splashScreen.view];

 [splashScreen displayScreen];
[self.window makeKeyAndVisible];

return YES;
 }

推荐答案

在视图控制器中try 此方法:

// swift
self.navigationController?.setNavigationBarHidden(true, animated: true)

// objective-c
[self.navigationController setNavigationBarHidden:YES animated:YES]; 

更多说明:

UINavigationController有一个属性navgationBarHidden,它允许您隐藏/显示整个导航控制器的导航栏.

让我们看看下一个层次 struct :

--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3

三个UIViewController中的每一个都有相同的导航栏,因为它们都在UINavigationController中.例如,您希望隐藏UIViewController2的栏(实际上在哪个栏中并不重要),然后在您的UIViewController2中写入:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];   //it hides the bar
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows the bar back
}

Ios相关问答推荐

SwiftUI文本编辑器内部滚动填充,无需文本裁剪

在相机动作之前快速防止场景视点重置

如何在iOS 17 SwiftUI中获取用户名

BezierPath 中绘制图像形状轮廓的算法(Canny 边缘检测器)

如何在 Flutter 应用程序中测试来自 App/Play Store 的移动深层链接?

如何链式设置 AttributeContainer 的 UIKit 属性?

不使用故事板创建 iMessage 应用程序

如何使用 pushViewController 从 UIHostingController 的 SwiftUI 视图中推送 ViewController?

DllImport with .a file for iOS in MAUI

Swift Combine 防止初始值触发接收器并同时防止重复?

滚动 swiftUI 列表时,未调用单元格的任务修饰符.怎么修?

UIViewControllerRepresentable 在 Xcode 14 iOS 16 上崩溃

在 Swift 中合并子数组

使用 Vim 代替(或与)Xcode 进行 iOS 开发

iPhone 6 和 6 Plus 媒体查询

警告:iPad:Icon-72.png:图标尺寸(0 x 0)

UIView 动画与 CALayers

UITextView 从文本的底部或中间开始

如何使用 AFNetworking 设置超时

具有两种不同字体大小的 NSAttributedString 示例?