hiding TabBar when rotating iPhone device to landscape

前端 未结 8 1617
旧时难觅i
旧时难觅i 2020-12-09 12:21

So here is what i have: A UITabBarController that handles different UIViewControllers. In one of the UIViewController i am trying to switch the view being displayed when the

8条回答
  •  被撕碎了的回忆
    2020-12-09 12:54

    This approach is working for me:

    - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    
        UIView *parentView = self.tabBarController.view;
        CGRect frame = parentView.frame;
        CGFloat windowHeight = parentView.window.frame.size.height;
    
        switch (toInterfaceOrientation) {
            case UIInterfaceOrientationLandscapeLeft:
            case UIInterfaceOrientationLandscapeRight:
                CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height;
                frame.size.height = windowHeight + tabBarHeight;
                break;
            default:
                frame.size.height = windowHeight;
                break;
        }
    
        [UIView animateWithDuration:duration animations:^{
            parentView.frame = frame;
        }];
    }
    

    (Only tested in iOS8.)

提交回复
热议问题