ios - 从不带导航栏的 View Controller 推送/弹出带导航栏的 View Controller

标签 ios objective-c iphone

我正在尝试从带有隐藏导航栏的 View Controller 推送带有可见导航栏的 View Controller 。

我在 viewWillAppear、viewDidAppear、viewWillDisappear 等中尝试了 [[self navigationController] setNavigationBarHidden:YES animated:NO]; 的各种组合。

// First View Controller

@implementation FirstViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[self navigationController] setNavigationBarHidden:YES animated:NO];

    NSLog(@"[%@ viewWillAppear]", self);
}

@end


// Second View Controller


@implementation SecondViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[self navigationController] setNavigationBarHidden:NO animated:NO];

    NSLog(@"[%@ viewWillAppear]", self);
}

@end

没有任何效果。我还尝试了自定义代码来“动画化”推送和弹出,这很有效,但我失去了边缘滑动和 View 平移。在我深入挖掘之前,只想确保我没有重新发明轮子。

Starbucks 应用程序是我试图模仿的。

应用程序的 Root View Controller (深色背景 View )是全屏的,请注意它没有 UINavigationBar。但是,当您点击其中一个按钮时,它会插入带有 UINavigationBar 的 View Controller (浅色背景 View )。从那里,如果您点击“后退”箭头,它会弹出带有导航栏的 View Controller 。交互式弹出滑动手势也有效。

Starbucks iOS App

最佳答案

无需自行破解解决方案即可。这是您要做的:

你的 Root View Controller :

@implementation ViewController

....

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

@end

和推送的 viewController:

@implementation SecondViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

@end

这样就可以了。它还使交互式过渡正常工作;)

然而,我发现令人不安的是,Apple 根本没有记录这种类型的功能。 - 您还可以使用这些“调用点”隐藏和显示工具栏(在 viewWillAppear: 内)

编辑

我刚刚意识到这与您在问题中编写的代码相同。请再次测试。我 100% 确定这有效——我也在我的一个应用程序中使用了这个功能。

另请注意,我的代码确实使用了 animated:animated 而不是您的 animated:NO。这可能是这里的关键点:)

关于ios - 从不带导航栏的 View Controller 推送/弹出带导航栏的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369046/

相关文章:

ios - Paypal ios 初始化使我的应用程序崩溃

ios - iPhone X UIScreen 返回高度,因为它是 iPhone 5

ios - 如何在 ios11.3 移动设备中调试 service worker/pwa?

iphone - 触摸 uiTabBar 上方

iphone - 在 View 中添加/删除 View 时出现问题

iphone - 同时按两个按钮

ios - TableView 不更新

ios - iOS 上的 AVCaptureAudioFileOutput 在哪里?

ios - 如何在 Objective-C 中将对象转换为类

ios - AVAudioPlayer 播放新声音时卡住 UI