iosobjective-capplettabbarsafearealayoutguide

The SafeArea insets are not updated when UITabbar is hidden


I am using the tab bar based app and on detail screen the tab bar is hidden. The issue is when the tab bar is hidden it will still occupy the white space that of tab bar and safeAreaLayoutInsets are not updated. On orientation change or moving from background to foreground it will work.

self.tabBarController.tabBar.hidden = YES;

View hierarchy

UITabbarController
  |--UISplitViewController
     |--UIViewController (first VC)
        |--UINavigationController
           |--UIViewController (second VC)

The issue is similar to one reported in Apple Forum


Solution

  • If you need to toggle the tab bar visibility of a visible view, this workaround fixes the layout:

    let currentFrame = tabBarController.view.frame
    tabBarController.view.frame = currentFrame.insetBy(dx: 0, dy: 1)
    tabBarController.view.frame = currentFrame
    

    This code should be executed immediately after the tab bar visibility is changed. It triggers an update of the safe area and a single layout pass of the view. The resizing of the frame is not visible to the user.

    It is a workaround and certainly not great, but it works for us and does not seem to have negative side effects. Moreover, I do not expect negative side effects in the future when iOS updates the layout by itself.