隐藏导航栏时,UIView不会调整为全屏。标签栏 [英] UIView doesn't resize to full screen when hiding the nav bar & tab bar

查看:299
本文介绍了隐藏导航栏时,UIView不会调整为全屏。标签栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个标签栏&导航栏用于正常交互。我的一个屏幕是文本的一大部分,所以我允许用户点击全屏(有点像Photos.app)。

I have an app that has a tab bar & nav bar for normal interaction. One of my screens is a large portion of text, so I allow the user to tap to go full screen (sort of like Photos.app).

导航栏和放大器;标签栏被隐藏,我将文本视图的框架设置为全屏。问题是,标签栏曾经是大约50px的空白区域。您可以在此屏幕截图中看到:

The nav bar & tab bar are hidden, and I set the the text view's frame to be full screen. The problem is, there is about 50px of white space where the tab bar used to be. You can see if from this screen shot:

已移除死亡的ImageShack链接

我不确定是什么原因引起的。空白绝对不是文本视图背后的视图,因为我将它的背景颜色设置为红色只是为了确定。可能导致这种情况的原因是什么?

I'm not sure what's causing this. The whitespace is definitely not the view behind the text view, as I set it's background color to red just to be sure. What could be causing this?

**更新**

我在UIWindow子类中做了一些命中测试并发现空白实际上是未记录/未发布的UILayoutContainerView。这是tabBar的父视图。我不认为建议直接操作此视图,那么如何隐藏标签栏?

I did some hit testing in a UIWindow subclass and found out that the whitespace is actually the undocumented/unpublished UILayoutContainerView. This is the parent view of the tabBar. I don't think it's recommended to directly manipulate this view, so how can I hide the tab bar?

**更新#2 **

** UPDATE # 2 **

我在&之前检查了self.view的框架在动画之后,看起来父视图的大小不够。

I checked self.view's frame before & after animation, and it looks like the parent view is not resizing enough.

在全屏显示之后,视图的帧只有411像素高。我已经尝试手动弄乱框架并且设置autoResizeMask没有运气。

after going fullscreen, the view's frame is only 411 pixels tall. I've tried messing with the frame manually and also setting autoResizeMask with no luck.

****更新:这是最终结果****

**** UPDATE: Here's the end result ****

- (void)toggleFullscreen {
    isFullScreen = !isFullScreen;  //ivar

    //hide status bar & navigation bar
    [[UIApplication sharedApplication] setStatusBarHidden:isFullScreen animated:YES];
    [self.navigationController setNavigationBarHidden:isFullScreen animated:YES];

    [UIView beginAnimations:@"fullscreen" context:nil];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:.3];

    //move tab bar up/down
    CGRect tabBarFrame = self.tabBarController.tabBar.frame;
    int tabBarHeight = tabBarFrame.size.height;
    int offset = isFullScreen ? tabBarHeight : -1 * tabBarHeight;
    int tabBarY = tabBarFrame.origin.y + offset;
    tabBarFrame.origin.y = tabBarY;
    self.tabBarController.tabBar.frame = tabBarFrame;

    //fade it in/out
    self.tabBarController.tabBar.alpha = isFullScreen ? 0 : 1;

    //resize webview to be full screen / normal
    [webView removeFromSuperview];
    if(isFullScreen) {
                //previousTabBarView is an ivar to hang on to the original view...
        previousTabBarView = self.tabBarController.view;
        [self.tabBarController.view addSubview:webView];

        webView.frame = [self getOrientationRect];  //checks orientation to provide the correct rect

    } else {
        [self.view addSubview:webView];
        self.tabBarController.view = previousTabBarView;
    }

    [UIView commitAnimations];
}

(请注意,我将textview切换为webview,但同样适用于原始版本文本视图)

(note that I switched textview to webview, but the same works for the original text view)

推荐答案

我有这个确切的问题,我在底部和顶部的标签栏和导航栏上设置了动画屏幕分别留下49px高的空白区域。标签栏是。

I had this exact problem where I was animating the tab bar and navigation bar off the bottom and top of the screen respectively, leaving a 49px high white space where the tab bar was.

事实证明,我的新全屏视图实际上没有填充空间的原因是因为我将全屏视图添加为导航控制器视图的子视图,该视图本身就是标签栏控制器的子视图。

It turns out that the reason my new "fullscreen" view wasn't actually filling the space was because I was adding the fullscreen view as a subview of the navigation controller's view, which itself was a child of the tab bar controller.

为了解决这个问题,我只是添加了新的全屏视图(在你的情况下是包含所有文本的视图)作为UITabBarController视图的子视图。

To fix it, I simply added the new fullscreen view (in your case the view with all the text) as a subview of the UITabBarController's view.


[[[self tabBarController] view] addSubview:yourTextView];

然后您需要做的就是确保您的子视图的帧是480 x 320px并且它应该填满屏幕(包括那个区域)以前是神秘的白色空间)

Then all you need to do is make sure that your subview's frame is 480 x 320px and it should fill the screen (including the area that was previously the mysterious white space)

这篇关于隐藏导航栏时,UIView不会调整为全屏。标签栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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