2009-07-10 73 views
37

我有一个应用程序,它具有用于正常交互的标签栏&导航栏。我的一个屏幕是文本的很大一部分,所以我允许用户点击去全屏(有点像Photos.app)。隐藏导航栏和标签栏时,UIView不会调整为全屏幕

导航栏&标签栏是隐藏的,我将文本视图的框架设置为全屏。问题是,标签栏曾经是空白的大约50px。你可以从这个截屏如果看到:

去除死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的web视图,但原始文本视图相同的作品)

+0

您的图像链接似乎已断开。如果您仍然有原始图像,请将其重新上传到stack.imgur,或者编辑您的问题以使其在没有图像的情况下工作。谢谢。 – 2015-07-27 14:41:27

回答

29

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

原来的原因,我的新的“全屏”的观点是不实际填充空间,是因为我加入了全屏视图导航控制器的视图的子视图,这本身就是标签栏控制器的孩子。

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

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

然后,所有你需要做的是确保你的子视图的框架是480 * 320像素,它应该充满整个屏幕(包括以前是神秘的白色空间的区域)

-1

添加额外的空间视图的维度,所以如果它是矩形CGRectMake(0,0,320,460)使它CGRectMake(0,0,320,480)...这发生在我身上,我不完全确定为什么,它可能会使用底层视图,将文本视图置于顶部,但只需添加维度即可。

+1

这没有任何影响。 – 2009-07-11 12:51:11

0

如果您正在使用Interface Builder,请确保在“大小”检查器中正确设置自动调整大小。 如果在代码中创建UITextView,请确保将帧设置得足够大,并且视图的父级(以及它的父级)也足够大。为了简单起见,直接将视图添加到窗口,然后从那里向内移动。

要移动以它的父:

- (void)moveViewToSuperview:(UIView *)view 
{ 
    UIView *newSuperview = [[view superview] superview]; 
    [view removeFromSuperview]; 
    [newSuperview addSubview:view]; 
    [newSuperview bringSubviewToFront:view]; 
} 
+1

自动尺寸是W + H。 textView.frame = CGRectMake(0,0,320,700);似乎对它没有影响。 – 2009-07-19 12:17:56

+0

如果我从视图中删除文本视图,然后直接将其添加到窗口,则它会全屏显示。虽然这有奇怪的自动旋转效果,所以我不能这样离开它。它似乎表明某些东西阻塞了文本视图。 – 2009-07-19 12:29:12

+0

试试这个:将你的UITextView返回到它在Interface Builder中的原始位置。添加一个调用来移动ViewToSuperview:myTextView在视图变为可见之后运行您的应用程序。测试它是否被遮挡。如果不是,请添加另一个呼叫并再次调试。冲洗重复。这应该可以帮助您找出阻止文本视图的视图的“多少层”。 – rpetrich 2009-07-21 03:28:43

2

也许有另一种观点认为是标签栏区域的内置部分?这就是说,还有一些可以隐藏的东西。这将有助于你看到周围有什么景象。

for (UIView *viewy in [self.navigationController.view subviews]) 
{ 
    NSLog([viewy description]); 
} 
+0

意见: > > > > (这显示了navigationController子视图和tabBarController子视图) – 2009-07-19 12:17:06

+0

这给了我一个想法,在白色区域做一个命中测试,看看出现了什么样的观点。我用更多的细节更新了这个问题。 – 2009-07-19 13:14:06

1

我认为,问题是,你仍然在标签栏控制器,我已经打了有这几个问题,以及,结束了创建我的应用程序的委托来控制,标签两种观点酒吧控制器和一个单独的uiview,它包含标签栏控制器试图执行的任何操作。您可以将您的视图传递给应用程序委托并在那里使用它?

+0

我不知道我跟着...你是说当我全屏使用不同的视图时?我试图直接将视图添加到UIWindow,它看起来不错,但旋转时的体验相当古怪。我不确定我想要走这条路。 – 2009-07-20 16:26:07

1

尝试使TabBarControllers查看比,使标签栏被隐藏关闭屏幕,屏幕更大,只要你做的新的视图控制器设置这个之前,那么它的视图将调整,以填补新的框架!

在我的测试中,我使用了tabBarController:shouldSelectViewController:delegate方法来检查哪个视图控制器即将变为当前并相应地设置TabBarController.view.frame。例如:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController 
{ 
    if(viewController == second) 
     tabBarController.view.frame = CGRectMake(0, 20, 320, 500); 
    else 
     tabBarController.view.frame = CGRectMake(0, 20, 320, 460); 
} 

如果这仍然不是很需要的,可以尝试寻找到的UIViewController的hidesBottomBarWhenPushed财产。当设置为yes时,如果控制器被压入导航堆栈,这将使底部栏隐藏。

1

当您选择全屏时,我会将视图移至窗口。例如

myView = [self.view retain]; 
self.view = nil; 
[window addSubview:myView]; 

,并回去:

[myView removeFromSuperView]; 
self.view = myView; 
[myView release]; 
myView = nil; 

通过添加视图作为窗口的子窗口,它可以完全全屏,并会在标签栏的顶部。

可以再用

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

结合该检测旋转。 (我认为你结合这与view.transform = CGAffineTransformMakeRotation使其旋转...?)

+0

当我这样做时让轮换工作的任何提示?如果我这样做,它似乎没有调用我的shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)方向方法。 – 2009-07-20 21:38:57

+0

您可以结合使用当前的解决方案: [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate :) name:@“UIDeviceOrientationDidChangeNotification”object:nil]; 检测旋转。 (我认为你把它和view.transform = CGAffineTransformMakeRotation结合起来使它旋转...?) 你可以从didRotate:函数调用你的shouldAutorotateToInterface ...函数来看看你是否也应该这么做。 – Benjie 2009-07-21 09:47:38

3

你是否已将视图控制器的hidesBottomBarWhenPushed属性设置为YES?您需要在您的initWithNibName:bundle:initWithCoder:方法中进行设置。当它被推送到导航控制器时,它应该隐藏标签栏并使内容视图向下延伸到底部。

0

您是否试图强制文本“重新写入”本身(重置您使用的任何对象的.text属性)?我有很多情况下,视图根本不会重新检查或重新绘制数据,强制似乎是唯一的修复方法。如果从用户体验的角度来看这是不好的,你可以尝试在用户触及之后,在他们消失之前使导航/标签栏变为透明。这通常将视图扩展到屏幕的全尺寸。

5

您可以通过移动视图的框架,使标签栏脱离屏幕来明确地做出正确的显示。我知道别人提到过这个问题,并且你说它不起作用,但我怀疑这个问题是你在尝试时没有正确设置textviews调整大小掩码。下面是代码,应该工作:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    currentlyHidden = NO; 
} 

- (void) hideStuff { 
    SO2AppDelegate *appDelegate = (id)[[UIApplication sharedApplication] delegate]; 
    self.navigationController.navigationBarHidden = YES; 

    CGRect newFrame = appDelegate.tabBarController.view.frame; 
    newFrame.size.height += appDelegate.tabBarController.tabBar.frame.size.height; 
    appDelegate.tabBarController.view.frame = newFrame; 
} 

- (void) showStuff { 
    SO2AppDelegate *appDelegate = (id)[[UIApplication sharedApplication] delegate]; 

    CGRect newFrame = appDelegate.tabBarController.view.frame; 
    newFrame.size.height -= appDelegate.tabBarController.tabBar.frame.size.height; 
    appDelegate.tabBarController.view.frame = newFrame; 

    self.navigationController.navigationBarHidden = NO; 
} 

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    if (currentlyHidden) { 
    [self showStuff]; 
    currentlyHidden = NO; 
    } else { 
    [self hideStuff]; 
    currentlyHidden = YES; 
    } 
} 

此外,因为这是你如何有你的笔尖等设置一定的敏感,我posting一个项目网上,这样你可以下载它,并得到看看吧。这是一个非常简单的演示,只是一个基于导航的项目,其中代表设置了一个选项卡控制器并从主要的笔尖嵌入视图控制器。剩下的就在RootViewController的nib和class中。无论何时开始触摸,酒吧都会切换,所以只需点击屏幕即可。显然,在一个真正的应用程序中,您可能需要调整滚动视图,以使内容看起来不会跳跃。

2

我发现,如果您将标记新视图您将推入导航堆栈,只要它位于堆栈上,下面一行隐藏标签栏。

scrollViewController.hidesBottomBarWhenPushed = YES;

0

如果的UITabBarController由RootViewController的(navigationController)推压。您可以尝试以下操作:

首先隐藏状态栏/选项卡栏;

[self.navigationController pushViewController:aBlankViewController animated:NO]; 
[self.navigationController popViewControllerAnimated:NO]; 

你应该能够收回的白色空间,但屏幕将在调整过程中震荡......

0

我已经经历了类似的问题,这种讨论是有益的:UIWebView on iPad size

Tony的回答让我发现,当你创建一个子视图是有帮助的设置代码与此类似:

self.tabBarController.tabBar.frame = self.view.bounds; 
0

认沽ŧ他代码准备像这样的赛格,对我来说很完美:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
if ([[segue identifier] isEqualToString:@"ViewPhoto"]) { 

    ImageView *vc = [segue destinationViewController]; 

    NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row]; 

     NSString *Title = [photoNames objectAtIndex:selectedIndex]; 
     [vc setSelectedTitle:[NSString stringWithFormat:@"%@", Title]]; 

     vc.hidesBottomBarWhenPushed = YES; 

     } 
    } 
1

我有类似的问题。正如Harry提到的那样,导航控制器是Tab Bar Controller内部控制器的原因。发现了另一种方式如何重绘您的观点,并有正确的框架,在您的控制器添加以下内容:

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    // Here you can make your tabBarControlelr.view.hidde = true or use any animation that hides UITabBar. I made 
    [TabBarController setTabBarHidden:YES]; 

    self.navigationController.view.frame = CGRectMake(self.navigationController.view.frame.origin.x, self.navigationController.view.frame.origin.y, self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height + 50); 
    [self.navigationController.view setNeedsLayout]; 

} 

这里是我如何隐藏它。我可以直接调用TabBarControlelr或类方法包装的方法:

+ (void)setTabBarHidden:(BOOL)hidden 
{ 
    AppDelegate *delegate = [UIApplication sharedApplication].delegate; 
    TabBarController *tabBarController = (TabBarController *) delegate.window.rootViewController; 

    if ([tabBarController isKindOfClass:[TabBarController class]]) { 
     [tabBarController setTabBarHidden:hidden]; 
    } 
} 


- (void)setTabBarHidden:(BOOL)hidden 
{ 
    if (self.tabBar.hidden == hidden) { 
     return; 
    } 

    if (hidden == NO) { 
     self.tabBar.hidden = hidden; 
    } 

    [UIView animateWithDuration:0.15 animations:^{ 
     self.tabBar.frame = CGRectOffset(self.tabBar.frame, 0, (hidden ? 50 : -50)); 
    } completion:^(BOOL finished) { 
     self.tabBar.hidden = hidden; 
    }]; 
}