我有一个应用程序,它有一个用于正常交互的标签栏和导航栏。我的一个屏幕是大部分文本,所以我允许用户点击进入全屏(有点像 Photos.app)。
导航栏和标签栏被隐藏,我将文本视图的框架设置为全屏。问题是,标签栏曾经所在的位置大约有 50 像素的空白区域。您可以从这个屏幕截图中看到:
删除了无效的 ImageShack 链接
我不确定是什么原因造成的。空白绝对不是文本视图后面的视图,因为我将它的背景颜色设置为红色只是为了确定。这可能是什么原因造成的?
** 更新 **
我在 UIWindow 子类中进行了一些命中测试,发现空白实际上是未记录/未发布的 UILayoutContainerView。这是 tabBar 的父视图。我认为不建议直接操作此视图,那么如何隐藏标签栏?
** 更新 #2 **
我在动画前后检查了 self.view 的帧,看起来父视图的大小调整不够。
全屏后,视图的框架只有 411 像素高。我试过手动弄乱框架,也没有运气设置 autoResizeMask。
****更新:这是最终结果****
- (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,但对于原始文本视图也是如此)