8

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

Raghav
  • 625
  • 1
  • 12
  • 31
  • 1
    while moving from first view try hide on push using `hidebottombarwhenpushed` – Vinodh Feb 28 '20 at 06:49
  • @Vinodh is correct hidebottombarwhenpushed will solve the problem, also check your constraints and make sure the bottom has safe area insets. – Manoj Feb 28 '20 at 10:44
  • 1
    I tried using `hidebottombarwhenpushed` but it didn't work with UISplitViewController – Raghav Mar 02 '20 at 07:56

1 Answers1

16

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.

Raginmari
  • 2,291
  • 23
  • 21