具有导航栏的推/弹出视图控制器,来自没有导航栏的视图控制器 [英] Push / Pop View Controller With Navigation Bar from View Controller Without Navigation Bar

查看:98
本文介绍了具有导航栏的推/弹出视图控制器,来自没有导航栏的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有隐藏导航栏的视图控制器推送带有可见导航栏的视图控制器。

I'm trying to push a view controller with a visible navigation bar from a view controller with a hidden navigation bar.

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

I tried all sorts of combinations of [[self navigationController] setNavigationBarHidden:YES animated:NO]; in viewWillAppear, viewDidAppear, viewWillDisappear... etc.

// 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

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

Nothing worked. I also tried custom code to "animate" a push and pop, which works, BUT I lose the edge swipe and view panning. Before I dig deeper, just want to make sure I'm not reinventing the wheel.

星巴克应用程序正是我试图模仿的。

The Starbucks app is what I'm trying to mimic.

应用程序的根视图控制器(深色背景视图)是全屏,并注意它没有UINavigationBar。但是,当您点击其中一个按钮时,它会使用UINavigationBar推动视图控制器(浅色背景视图)。从那里,如果您点击后退箭头,它会查看控制器弹出导航栏。交互式弹出滑动手势也可以。

The root view controller of the app (the dark background view) is full screen and notice how it doesn't have a UINavigationBar. But when you tap on one of the buttons, it pushes on a view controller (the light background view) WITH a UINavigationBar. From there, if you tap the "back" arrow, it view controller pops with the navigation bar. Interactive pop swipe gesture also works.

推荐答案

可以自行解决一个解决方案。以下是您的工作:

It is possible without hacking together a solution by yourself. Here is what you do:

您的根视图控制器:

@implementation ViewController

....

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

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

@end

推送的viewController:

And the pushed viewController:

@implementation SecondViewController

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

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

@end

这样做。它还使交互式过渡保持工作;)

This will do. It also keeps the interactive transition working ;)

然而,我觉得令人不安的是,苹果公司根本没有记录这种类型的功能。 - 您还可以使用这些呼叫点隐藏和显示工具栏(在viewWillAppear内部)

I find it disturbing, however, that this type of functionality is not documented at all by apple. - You can also hide and show toolbars with these 'call-points' (inside viewWillAppear:)

编辑

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



请注意我的代码确实使用动画:动画而不是你的动画:否。这可能是关键点:)

I just realized that this is the same code you wrote in your question. Please test it again. I am 100% sure that this works - I used this functionality in one of my apps, too.

Please also note that my code does use animated:animated instead of your animated:NO. This may be the crucial point here :)

这篇关于具有导航栏的推/弹出视图控制器,来自没有导航栏的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆