如何在第一次加载时隐藏 tabBar,并在以后的屏幕上显示?

发布于 2024-09-14 12:36:17 字数 102 浏览 4 评论 0原文

.hidesBottomBarWhenPushed = 否;不起作用,因为视图没有被推送。我希望 tabBar 在第一个屏幕上隐藏,并能够在几个屏幕后再次显示。

我该怎么做?

.hidesBottomBarWhenPushed = NO; doesn't work because the view isn't getting pushed. I want the tabBar to be hidden on the first screen and able to show it again a few screens later.

How can I do this?

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

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

发布评论

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

评论(2

〃安静 2024-09-21 12:36:17

子类化你的 UITabBarController 并添加一个像这样的函数

- (void) hideTabBar:(BOOL)hide animated:(BOOL)animated {

    if (tabBarHidden == hide) { return; }

    if (animated) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.5];
    }

    for(UIView *view in self.view.subviews) {

        if([view isKindOfClass:[UITabBar class]]) {

            if (!hide) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (!hide) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49)];
            }

        }
    }

    if (animated) { [UIView commitAnimations]; }

    tabBarHidden = hide;

}   

当你在做的时候,添加一个像这样的函数来允许标签栏旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return allowRotate;
} 

Subclass your UITabBarController and add a function like this

- (void) hideTabBar:(BOOL)hide animated:(BOOL)animated {

    if (tabBarHidden == hide) { return; }

    if (animated) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.5];
    }

    for(UIView *view in self.view.subviews) {

        if([view isKindOfClass:[UITabBar class]]) {

            if (!hide) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (!hide) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49)];
            }

        }
    }

    if (animated) { [UIView commitAnimations]; }

    tabBarHidden = hide;

}   

Whilst your at it, add a function like this to allow the tab bar to rotate

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return allowRotate;
} 
眼前雾蒙蒙 2024-09-21 12:36:17

这将很困难,因为选项卡栏被设计为应用程序 UI 的顶层。文档对此非常清楚。因此,它们在不在顶层的控制器层次结构中表现不佳。

实际上,完成您想要的操作的唯一方法是在您希望它出现时以编程方式创建选项卡栏。但是,我不能说这会产生可靠的代码。标签栏将一路与你战斗。

你真的应该重新考虑你的 UI 设计。以非标准方式使用选项卡栏会让您的用户感到困惑。由于标准是在 UI 的顶层设置选项卡栏,因此当用户看到选项卡栏时,他们会认为自己处于顶层。他们会迷失方向。您确实需要坚持标准用法,以便您的应用程序符合用户已经学习的界面语法。

请参阅 iPhone 人机界面指南。

This is going to be difficult because tabbars are designed to be the top level of the application's UI. The documentation is very clear on this. As such, they don't play well in a controller hierarchy in which they are not on top.

Really the only way to accomplish what you want is programmatically create the tabbar when you want it to appear. However, I can't say that will produce reliable code. The tabbar will be fighting you all the way.

You really should rethink your UI design. Using the tabbar in a non-standard way will confuse your users. Since the standard is to have tabbars at top level of the UI, users will believe they are at the top level when they see a tabbar. They will get disoriented. You really need to stick to standard usage so that your app agrees with the interface grammar that the users have learned.

See the iPhone Human Interface Guidelines.

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