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

后端 未结 15 1578
情歌与酒
情歌与酒 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: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.

提交回复
热议问题