Iphone UIView没有';t隐藏导航栏时,将大小调整为全屏&;标签栏

Iphone UIView没有';t隐藏导航栏时,将大小调整为全屏&;标签栏,iphone,iphone-sdk-3.0,uitextview,Iphone,Iphone Sdk 3.0,Uitextview,我有一个应用程序,它有一个选项卡栏和导航栏,用于正常的交互。我的一个屏幕是很大一部分文本,所以我允许用户点击进入全屏(有点像Photos.app) 导航栏和选项卡栏是隐藏的,我将文本视图的框架设置为全屏。问题是,选项卡栏原来所在的位置有大约50px的空白。您可以从这个屏幕截图中看到: 拆下固定的影像棚链接 我不确定是什么原因造成的。空白绝对不是文本视图后面的视图,因为我将其背景色设置为红色只是为了确定。这可能是什么原因造成的 **更新** 我在UIWindow子类中做了一些命中测试,发现空白实际

我有一个应用程序,它有一个选项卡栏和导航栏,用于正常的交互。我的一个屏幕是很大一部分文本,所以我允许用户点击进入全屏(有点像Photos.app)

导航栏和选项卡栏是隐藏的,我将文本视图的框架设置为全屏。问题是,选项卡栏原来所在的位置有大约50px的空白。您可以从这个屏幕截图中看到:

拆下固定的影像棚链接

我不确定是什么原因造成的。空白绝对不是文本视图后面的视图,因为我将其背景色设置为红色只是为了确定。这可能是什么原因造成的

**更新**

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

**更新#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,但对原始文本视图也适用)

将额外的空间量添加到视图的维度中,因此,如果它是矩形CGRectMake(0,0320460),则将其设置为CGRectMake(0,0320480)。。。这种情况发生在我身上,我不太清楚为什么,这可能与您将文本视图置于顶部的基础视图有关,但只需添加维度就可以了

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

要将视图移动到其superview,请执行以下操作:

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

也许还有另一个视图是选项卡栏区域的内置部分?也就是说,有一些额外的东西需要隐藏。这将帮助您查看周围的视图

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

我相信问题在于您仍然在选项卡栏控制器中,我也遇到了一些问题,最后为我的应用程序委托创建了两个视图,选项卡栏控制器和一个单独的uiview,其中包含选项卡栏控制器试图控制的任何内容。您可以将视图传递给app delegate并在那里使用它?

尝试使TabBarControllers视图大于屏幕,以便在屏幕外隐藏选项卡栏,只要在设置新的ViewController之前执行此操作,则其视图将调整大小以填充新的框架

在测试中,我使用了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属性。当设置为“是”时,如果控制器被推到导航堆栈上,这将使底部栏隐藏。

当您选择全屏显示时,我会将视图移动到窗口。e、 g

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结合使用以使其旋转…?)

是否已将视图控制器的
HidesBottomBarWhenPush
属性设置为
YES
?您需要在
initWithNibName:bundle:
initWithCoder:
方法中设置此选项。当它被推送到导航控制器时,这将隐藏选项卡栏,并使内容视图向下延伸到底部。

您是否尝试强制文本自身“重写”(重置正在使用的任何对象的.text属性)?我曾经有过很多这样的例子,视图根本不重新检查或重新绘制它们的数据,而强制似乎是唯一的修复方法。如果从用户体验的角度来看这不好,您可以尝试在用户触摸导航/选项卡栏之后,以及它们消失之前,使其透明。这通常会将视图扩展到屏幕的全部大小。

通过移动视图框架,使选项卡栏脱离屏幕,您完全可以做出正确的显示。我知道有人提到尝试过,而你说它不起作用,但我怀疑问题是你在尝试时没有正确设置textviews resize mask。下面是应该工作的代码:

- (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;
  }
}

此外,由于这肯定是敏感的,你如何有你的nibs等设置,我是一个在线项目,所以你可以下载它,看看它。这是一个非常简单的演示,只是一个基于导航的项目,在该项目中,代理设置一个选项卡控制器,并从主nib嵌入视图控制器。其余部分在RootViewController nib和类中。每当触摸开始时,这些条都会切换,因此只需轻触屏幕即可。显然,在一个真正的应用程序中,你可能需要调整滚动视图,这样内容就不会出现跳跃。

我遇到了这个问题,我分别在屏幕底部和顶部设置了选项卡栏和导航栏的动画,在选项卡栏所在的位置留下了49像素高的空白

事实证明,我的新“全屏”视图没有真正填满空间的原因是,我将全屏视图添加为导航控制器视图的子视图,而导航控制器视图本身是选项卡栏控制器的子视图

为了解决这个问题,我简单地添加了新的全屏视图(在您的例子中是视图wi) [[[self tabBarController] view] addSubview:yourTextView];
[self.navigationController pushViewController:aBlankViewController animated:NO];
[self.navigationController popViewControllerAnimated:NO];
self.tabBarController.tabBar.frame = self.view.bounds;
- (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;

        }
    }
- (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];

 }
+ (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;
    }];
}