没有导航栏的 UINavigationController

发布于 2024-10-17 20:27:18 字数 276 浏览 1 评论 0原文

我有一个“登陆页面/视图”,我不希望导航栏显示,所以我在 viewDidAppear 期间将其关闭,

navigationBarHidden = YES;

当我将视图推送到堆栈上然后将其移开时。主登陆页面显示导航栏然后隐藏它,这会导致我不想要的闪烁。

有没有办法让登陆页面成为 UIView 之类的?当触摸菜单项时,应用程序会将新视图推送到默认登录页面顶部。听起来如果没有 UINavigationController 登陆页面就很难做到。有什么想法吗?

I have a "landing page/view" that I dont want the navigation bar to show, so I turn it off during the viewDidAppear

navigationBarHidden = YES;

When i push a view on the stack and then move it off. the main landing page shows the nav bar then hides it which cause a flicker that I dont want.

is there a way to have the landing page be a UIView or something? When a menu item is touched the app would push a new view on top of the default landing page. It sound like it would be hard to do without having the landing page be a UINavigationController. Any thoguhts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

手长情犹 2024-10-24 20:27:18

尝试在 viewWillAppear 中隐藏导航栏,而不是在 viewDidAppear 中。

Try hiding the navigation bar in viewWillAppear, rather than viewDidAppear.

深巷少女 2024-10-24 20:27:18

如果您不需要返回登录页面,请为登录页面使用视图控制器,并在应用程序启动时从导航控制器以模态方式呈现它。


所以您确实想返回登录页面。

使用 UINavigationController 很难实现这一点。假设您要返回着陆视图。在转换时,旧视图应该有导航栏,而新视图(登陆页面)不应该有导航栏。 UINavigationController 不允许您手动修改过渡动画。换句话说,您无法将隐藏/取消隐藏导航栏与推送/弹出动画一起设置动画(使用 viewWillAppear 并不能解决问题)。

那么,如果我真的非常需要这个,我该怎么办?

我将有一个 rootViewController(UIViewController),其视图是应用程序窗口的唯一子视图。当您的应用程序启动时,rootViewController 将登陆视图添加为其视图的子视图。当用户选择其中的某个项目时,您将创建一个 UINavigationController,并将相应的视图控制器作为其根视图控制器。

并且,使用 kCATransitionPush 类型和 kCATransitionFromRight 子类型的 CATransition 动画,将导航控制器的视图添加为 的子视图rootViewController 的视图。

然后,您需要一个“后退”按钮来显示导航控制器的第一个视图。在作为导航控制器的第一级视图控制器的所有视图控制器中,创建一个带有文本“Back”的栏按钮项,并将其添加到其 navigationItem.leftBarButton 属性中。为按钮设置一个目标操作(可能是 rootViewController)对。

当操作消息触发时,使用 CATransition 动画(现在具有 kCATransitionFromLeft 子类型)从 rootViewController 的视图中删除当前导航控制器的视图。

过渡可能看起来不像原生 UINavigationController 那样完美,但我相信这是您可以获得的最好效果。

If you don't need to go back to the landing page, use a view controller for the landing page and present it modally from the navigation controller when the application starts.


So you do want to go back to the landing page.

It's hard to accomplish that with UINavigationController. Suppose your are going back to the landing view. While the transition, the old view should have a navigation bar, and the new view (landing page) should not have a navigation bar. UINavigationController does not allow you manually modifying the transition animation. In other words, you cannot animate hiding/unhiding the navigation bar along with push/pop animation (using viewWillAppear doesn't solve the problem).

So what would I do, if I really, really need this?

I would have a rootViewController (of UIViewController), whose view is the only subview of your application window. When your application starts, rootViewController add the landing view as a subview of its view. When the user selects an item there, you create an UINavigationController with the corresponding view controller as its root view controller.

And, using CATransition animation with type of kCATransitionPush and subtype of kCATransitionFromRight, you add the view of the navigation controller as a subview of rootViewController's view.

Then you need a 'back' button for the first view of the navigation controller. In all view controllers that are the first level view controllers of the navigation controller, create a bar button item with a text 'Back', and add it to their navigationItem.leftBarButton property. Set a target-action (probably to the rootViewController) pair for the button.

When the action message fires, use CATransition animation (now with kCATransitionFromLeft subtype), to remove the current navigation controller's view from rootViewController's view.

The transition may not look as perfect as the native UINavigationController, but I believe this is the best you could get.

善良天后 2024-10-24 20:27:18

实际上,实现这一点的方法是实现 UINavigationController 的委托方法 navigationController:willShowViewController:animated。您应该在此方法中处理导航栏的隐藏和显示,以便动画将在推送/弹出动画期间发生。

Actually the way to do this is to implement UINavigationController's delegate method navigationController:willShowViewController:animated. This method is where you should handle hiding and showing your navigation bar so the animation will occur during the push/pop animation.

夏有森光若流苏 2024-10-24 20:27:18

我发现了一种简单且适合我的方法,这里尚未给出。我假设您有一个用于主登陆页面的视图控制器,并且它被设置为导航控制器的根视图控制器。然后,您应该在主登陆页面控制器的 viewWillAppear 和 viewWillDisappear 方法中隐藏/显示导航栏:

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

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

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

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

来源:
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/

I came across a method that is simple and works well for me, and is not given here yet. I assume you have a view controller for the main landing page and it is set as root view controller of the navigation controller. Then you should hide/show the navigation bar in the viewWillAppear and viewWillDisappear methods of the main landing page controller:

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

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

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

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

Source:
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文