UIView doesn't resize to full screen when hiding the nav bar & tab bar

后端 未结 15 1470
情歌与酒
情歌与酒 2020-12-02 07:28

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 l

相关标签:
15条回答
  • 2020-12-02 08:04

    I believe the issue is that you're still in the tab bar controller, I've hit a few issues with this as well, and ended up creating two views for my app delegate to control, the tab bar controller , and a separate uiview that holds anything that the tab bar controller tries to take command of. You could pass your view to the app delegate and use it there perhaps?

    0 讨论(0)
  • 2020-12-02 08:05

    You can definitely make something that appears correct by shifting the frame of the view such that the tab bar is off screen. I know someone else mentioned trying that, and you said it didn't work, but I suspect the issue is that you did not have the textviews resize mask setup properly when you tried. Below is code that should work:

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

    Additionally, since this is definitely sensitive to how you have your nibs etc setup, I am posting a a project online so you can download it and get a look at it. It is a pretty minimal demo, just a Navigation based project where the delegate sets up a tab controller and embeds the view controller from the main nib. The rest is in the RootViewController nib and class. The bars are toggled whenever a touch begins, so just tap the screen. Obviously in a real app you might need to adjust the scroll view so stuff the content doesn't appear to jump.

    0 讨论(0)
  • 2020-12-02 08:09

    Have you attempted to force the text to "re-write" itself (resetting the .text property of whatever object you're using)? I have had many instances where views simply do not re-check or repaint their data, and forcing seems to be the only fix. If this is not good from a user experience standpoint, you might try making the nav/tabbars transparent after the user touches, and before they disappear. This normally extends the view to the full size of the screen.

    0 讨论(0)
  • 2020-12-02 08:11

    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.

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

    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)

    0 讨论(0)
  • 2020-12-02 08:11

    I had similar issue. As Harry mentioned it's a reason of Navigation Controller that is inner controller of Tab Bar Controller. Found another way how to redraw your view and have correct frame., In your controller add following:

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

    And here is how I hide it. I can make it directly calling method of TabBarControlelr or class method wrapper:

    + (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;
        }];
    }
    
    0 讨论(0)
  • 2020-12-02 08:11

    I would move the view to the window when you choose to go fullscreen. e.g.

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

    and to go back:

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

    By adding the view as a child of the window, it can be totally fullscreen and will be on top of the tab bar.

    You can then combine this with

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

    to detect rotation. (I think that you combine this with view.transform = CGAffineTransformMakeRotation to make it rotate...?)

    0 讨论(0)
提交回复
热议问题