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

后端 未结 15 1565
情歌与酒
情歌与酒 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: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;
        }];
    }
    

提交回复
热议问题