UITabBar 隐藏时留下白色矩形

发布于 2024-08-24 08:54:06 字数 412 浏览 9 评论 0原文

我无法在谷歌上找到可以应用于我的项目的可接受的解决方案。

我的应用程序是一个图形工具,具有三个选项卡;一个用于图表本身,另外两个用于浏览/搜索可添加到图表中的内容的功能。所有选项卡都是导航控制器。

当处于纵向模式时,图表本身的选项卡会显示图表的小预览并列出下面图表中每个实体的详细信息,并在底部显示选项卡栏。

当用户旋转到横向模式时,图表将变成全屏,其他所有内容(包括选项卡栏)都会消失。这就是我遇到问题的地方,因为我的图形的 GLView 总是被选项卡栏所在的白色矩形遮挡。

我尝试将导航控制器视图的大小更改为全屏,将选项卡栏控制器视图的大小更改为全屏,将选项卡栏本身的框架大小更改为 CGRect(0,0,0,0),情绪变得心烦意乱,用拳头敲桌子,对着 MacBook 大声辱骂等等;一切都无济于事。

我怎样才能让它发挥作用?

I have been unable to google an acceptable solution to this that can be applied to my project.

My app is a graphing tool that has three tabs; one for the graph itself and the other two are for browse/search functions for things that can be added to the graph. All tabs are navigation controllers.

The tab for the graph itself, when in portrait mode, displays a small preview of the graph and lists details of each entity that is on the graph below, and displays the tab bar at the bottom.

When the user rotates into landscape mode the graph turns full screen and everything else, including the tab bar, disappears. This is where I'm having the problem, as the GLView for my graph is always obscured by a white rectangle where the tab bar was.

I have tried changing the size of the navigation controllers view to full screen, changing the size of the tab bar controllers' view to full screen, changing the frame size of the tab bar itself to CGRect(0,0,0,0), becoming emotionally distraught, banging my fists on the desk, shouting abusive language at the MacBook, etc; all to no avail.

How can I make it work?

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

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

发布评论

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

评论(18

夏雨凉 2024-08-31 08:54:06

我遇到了这个问题,我通过更改内容视图的选项卡栏子视图框架解决了这个问题(选项卡栏有 2 个子视图 - 内容视图 (#0) 和栏视图 (#1)):

[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:FULLSCREEN_FRAME];

I had this problem, and I've resolved it by changing tabbar's subview frame for my content view (there are 2 subviews in tab bar - content view (#0) and bar view (#1)):

[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:FULLSCREEN_FRAME];
青巷忧颜 2024-08-31 08:54:06

我遇到了同样的问题,并在这里找到了答案:隐藏导航栏和隐藏导航栏时 UIView 不会调整为全屏标签栏

只需调整 tabbarcontroller 的大小即可在隐藏标签栏时查看此内容:

tabBarController.view.frame = CGRectMake(0, 0, 320, 480);

I had the same problem and found the answer here : UIView doesn't resize to full screen when hiding the nav bar & tab bar

just resize the tabbarcontroller view this when you hide the tabbar :

tabBarController.view.frame = CGRectMake(0, 0, 320, 480);
风和你 2024-08-31 08:54:06

似乎存在将底部栏隐藏为选项卡栏的问题......我面临着这个问题,并为此进行了很多谷歌搜索。我认为这是此选项卡栏的一个错误。然后......我们可以使用一些技巧......

你可以尝试这个,如果你试图隐藏标签栏并留下空白,肯定会有所帮助......

对于地狱般的编码,你需要

[self setHidesBottomBarWhenPushed:YES];

在推送到其他视图时编写,在您不需要选项卡栏的地方只需编写它

twitDetObj=[[TwitDetail alloc] initWithNibName:@"TwitDetail" bundle:nil];
[self.navigationController pushViewController:twitDetObj animated:YES];
self.hidesBottomBarWhenPushed=YES;
[twitDetObj release];

希望这对您有用......

It seems to have the problem with hiding the Bottom bar as Tab bar.... which I was facing and googled a lot for this.I consider it as a bug with this tab bar.Then also....we can use some trick.....

You can try for this and will definitely help if you are trying to hide the tab bar and which leaves the white space..

for the hell of coding you need to write just

[self setHidesBottomBarWhenPushed:YES];

when you are pushing to other view,where you don't need the Tab bar just write it

twitDetObj=[[TwitDetail alloc] initWithNibName:@"TwitDetail" bundle:nil];
[self.navigationController pushViewController:twitDetObj animated:YES];
self.hidesBottomBarWhenPushed=YES;
[twitDetObj release];

Hope this will work for you.....

沩ん囻菔务 2024-08-31 08:54:06

这对我有用:

[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];

我在选项卡的 viewControllers 中有这段代码。

This one works for me:

[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];

I had this code within the tab's viewControllers.

标点 2024-08-31 08:54:06

注意 - 此解决方案只是删除隐藏选项卡栏后留下的空白。

对于隐藏选项卡栏,最佳解决方案是 - @Michael Campsall 在这里回答

最简单的解决方案是更改您的视图(在我的如果是它的 tableView) 底部约束,而不是使用 BottomLayoutGuide 给出底部约束,而是使用 superview 给出底部约束。附上截图供参考。

下面屏幕截图中显示的约束会产生问题,请根据下一个屏幕截图进行更改

在此处输入图像描述

删除空白的实际约束应根据此(如下)屏幕截图。

输入图片此处描述

NOTE - This solution is to just to remove white space left after hiding tab bar.

For hiding tab bar best solution is - @Michael Campsall answer here

The simplest solution to this is to change your view's(in my case its tableView) bottom constraints, instead of giving bottom constraints with BottomLayoutGuide give it with superview. Screenshots attached for reference.

Constraints shown in below screenshots creates the problem, change it according to next screenshot

.enter image description here

Actual constraints to remove white space should be according to this(below) screenshot.

enter image description here

她比我温柔 2024-08-31 08:54:06

对于那些仍在为此苦苦挣扎的人。我发现问题出在限制上。选项卡栏被隐藏,但它已经改变了我对情节提要的限制。

SWIFT 3+

self.tabBarController?.tabBar.isHidden = true

let cons = NSLayoutConstraint(item: textview, attribute: NSLayoutAttribute.bottom,
         relatedBy: NSLayoutRelation.equal, toItem: self.view, 
         attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 0)

view.addConstraints([cons])

在我的例子中,“textview”是一个项目,它应该填充隐藏 TabBar 中的空白区域。

For those who is still struggling with this. I have found that the problem lays on the constraints. Tab Bar is hidden, yet it already changed my constraint from Storyboard.

SWIFT 3+

self.tabBarController?.tabBar.isHidden = true

let cons = NSLayoutConstraint(item: textview, attribute: NSLayoutAttribute.bottom,
         relatedBy: NSLayoutRelation.equal, toItem: self.view, 
         attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 0)

view.addConstraints([cons])

In my case "textview" was the item, which supposed to fill the white space from hidden TabBar.

灵芸 2024-08-31 08:54:06

你确定它被遮挡了,而不仅仅是A)没有重绘或者B)你的GLView的框架没有占据那个空间?

Are you sure it's obscured and not just A) not redrawn or B) the frame of your GLView doesn't occupy that space?

旧夏天 2024-08-31 08:54:06

选项卡栏视图控制器的 currentViewController.view 的一些超级视图将 ClipToBounds 设置为 YES(如果没有记错的话,它的类名称是 UITransitionView)。要访问它,

tabBarController.currentViewController.view.superview.superview.clipToBounds = NO;

执行此操作后,您调整视图大小的尝试将不会受到任何限制并且将会成功。祝你好运!

some of the superviews of currentViewController.view of the tab bar view controller has clipToBounds set to YES (it's class name is UITransitionView, if not mistaken). To access it use

tabBarController.currentViewController.view.superview.superview.clipToBounds = NO;

after doing this your attempts of resizing a view will not be limited by anything and will succeed. Good luck!

背叛残局 2024-08-31 08:54:06

这只是一种解决方法,但是您是否尝试过在用户旋转到横向时以模态方式呈现图形?这应该会遮盖标签栏。

避免转换

您可以使用[viewControllerpresentModalViewController:graphanimated:NO]

This is just a workaround, but have you tried presenting the graph modally when the user rotates to landscape? This should obscure the tab bar.

You can avoid the transition with

[viewController presentModalViewController:graph animated:NO]

郁金香雨 2024-08-31 08:54:06

这是因为当你设置标签栏隐藏时,标签栏所在的空间没有分配给其他视图,你可以设置相应的视图来拉伸或填充整个屏幕,例如比例填充或长宽比填充之类的东西,或者采取比 iphine 更大的视图屏幕,以便当您将手机更改为横向时,它可以完全填满屏幕

its because the space where tab bar was , not allocated to other views when u set tab bar hidden u can set the corresponding view to stretch or fill the whole screen like scale fill or aspect fill something like that or take a view bigger than the iphine screen so that when u change the phone to landscape it can complete fill the screen

终弃我 2024-08-31 08:54:06

检查下面的 UIView。它可能设置为白色,因此当您隐藏选项卡时,您会显示白色的 UIView。尝试将 UIView 设置为透明。

Check the UIView underneath. It may be set to white, so when you hide the tab you're revealing the white UIView. Try setting the UIView to Transparent.

烟酉 2024-08-31 08:54:06

我认为你需要在设置选项卡栏隐藏之前将 self.navigationController.view.frame 设置为全尺寸,即 UIApplication 屏幕框架

I think u need to set self.navigationController.view.frame to full size ie to UIApplication screen frame before u set tabbar hidden

独夜无伴 2024-08-31 08:54:06

取消隐藏 tababr 并到达特定视图后打开。标签栏在 uitababr 上方显示空白。这解决了我的问题

-(void)viewWillAppear:(BOOL)animated
{ 
    [[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 568)];

}

On after unhiding tababr and reaching to particular view. Tabbar was showing white space on above uitababr. This solved my problem

-(void)viewWillAppear:(BOOL)animated
{ 
    [[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 568)];

}
涫野音 2024-08-31 08:54:06

在视图中推送

- (BOOL)hidesBottomBarWhenPushed
{
    return YES;
}

in the view pushed

- (BOOL)hidesBottomBarWhenPushed
{
    return YES;
}
哽咽笑 2024-08-31 08:54:06
- (void)hidesTabBar:(BOOL)hidden {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];

    for (UIView *view in self.tabBarController.view.subviews) {
        if ([view isKindOfClass:[UITabBar class]]) {
            if (hidden) {
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if([view isKindOfClass:NSClassFromString(@"UITransitionView")]) {
                if (hidden) {
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
                } else {
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
                }
            }
        }
    }

    [UIView commitAnimations];
}
- (void)hidesTabBar:(BOOL)hidden {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];

    for (UIView *view in self.tabBarController.view.subviews) {
        if ([view isKindOfClass:[UITabBar class]]) {
            if (hidden) {
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if([view isKindOfClass:NSClassFromString(@"UITransitionView")]) {
                if (hidden) {
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
                } else {
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
                }
            }
        }
    }

    [UIView commitAnimations];
}
在风中等你 2024-08-31 08:54:06

我的解决方案:在视图控制器的 viewDidLoad() 中设置 self.edgesForExtendedLayout = .None

My solution: set self.edgesForExtendedLayout = .None in your view controller's viewDidLoad().

你曾走过我的故事 2024-08-31 08:54:06

我假设您已经检查了视图上的自动调整大小箭头?

I'm assuming that you've already checked the autoresizing arrows on your view?

半夏半凉 2024-08-31 08:54:06

您是否尝试过隐藏 UITabBar

tab_bar.hidden = YES

Have you tried hiding the UITabBar with

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