如何使按钮仅在 UITabBar 的 5 个选项卡中的 3 个中显示 UINavigationBar?

发布于 2024-08-26 10:46:19 字数 338 浏览 6 评论 0原文

我有一个应用程序,其中有一个带有 5 个选项卡的 UITabBar。当用户摇动设备时,我希望 UINavigationBar 推送 UIImageView。当我显示 UIImageView 时,我需要隐藏选项卡和导航栏。之后,当用户点击 UIImageView 时,导航栏再次出现,用户可以转到 UIImageView 的父视图。我使导航栏显示如下:

[[self navigationController] setNavigationBarHidden:NOanimated:YES];

但在两个选项卡中,我必须使导航栏出现,以便用户可以切换到 UIImageView 的父视图,然后当父视图出现时,隐藏导航栏。我该怎么做呢?

I have an app, where there's a UITabBar with 5 tabs. When user shakes the device, I want the UINavigationBar to push an UIImageView. When I show the UIImageView, I need to hide both tab and nav bars. After that, when user taps the UIImageView, the NavBar appears again and user can go to the UIImageView's parent view. I make the Nav Bar appear like this:

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

But in two tabs I have to make the Nav Bar appear, so user can switch to UIImageView's parentView and then, when the parent view appears, hide the nav bar. How can I do it?

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

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

发布评论

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

评论(2

三寸金莲 2024-09-02 10:46:19

我认为你应该设置一个 UITabBarController 委托并实现这个方法:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // Put real logic here
    BOOL shouldHideNavBar = (viewController == myViewController1 || viewController == myViewController4);
    [[self navigationController] setNavigationBarHidden:shouldHideNavBar animated:YES];
}

I think you should set up a UITabBarController delegate and implement this method:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // Put real logic here
    BOOL shouldHideNavBar = (viewController == myViewController1 || viewController == myViewController4);
    [[self navigationController] setNavigationBarHidden:shouldHideNavBar animated:YES];
}
凤舞天涯 2024-09-02 10:46:19

这比我想象的要容易。我只需要把

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

That was easier than I thought. I just have to put

- (void)viewDidAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:NO]; 
    [super viewDidAppear:animated];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文