Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabBar moving up whenever a ViewController is pushed in iPhone X

I've recently added support to iOS 11 on my app and this started happening. Basically, whenever a ViewController is added to the navigation stack the tab bar glitches out during the animation.

It only happens in iPhone X, and this is just a regular TabBarController. What's causing it?

What's going on

like image 588
Bruno Rocha Avatar asked Oct 03 '17 18:10

Bruno Rocha


People also ask

How do I add a Viewcontroller to the tab bar controller in storyboard?

To add the new View Controller to the Tab Bar Controller, right-click the Tab Bar Controller and drag it to the new View Controller. Select Relationship Segue. Now, the Tab Bar Controller has the third item and Relationship “view controllers” to “View Controller”.

How do I hide a Tabbar in Swift?

UITabBarController+ToggleTabBar.swift Show or hide the tab bar. - Parameter hidden: `true` if the bar should be hidden. - Parameter animated: `true` if the action should be animated.

What is tab bar controller in Swift?

What's A Tab Bar Controller? A tab bar controller, of class UITabBarController, is a container view controller. It typically organizes 3-5 view controllers in a group. The user of your app can switch between view controllers by tapping one of the tabs in the tab bar at the bottom of the screen.


1 Answers

Additional answer

A radar is open about this problem here.

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    // Disable tabBar shifts upward whenever a ViewController is pushed on iPhone X rdar://35098813
    BOOL isIPhoneX = ...
    if (isIPhoneX && UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
        [self.tabBar setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame) - CGRectGetHeight(self.tabBar.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.tabBar.frame))];
    }
}

Original answer

I think this is a bug of iOS 11. You can remove that weird effect to put down this code to your subclass of UITabBarController.

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    BOOL isIPhoneX = ...
    if (isIPhoneX && UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
        [self.tabBar setFrame:CGRectMake(0, self.view.frame.size.height - 83, 375, 83)];
    }
}

The solution is weird, too. :)

like image 186
MG Han Avatar answered Nov 15 '22 23:11

MG Han