The SafeArea insets are not updated when UITabbar is hidden
Asked Answered
H

1

10

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

Hickok answered 28/2, 2020 at 5:49 Comment(3)
while moving from first view try hide on push using hidebottombarwhenpushedHemmer
@Hemmer is correct hidebottombarwhenpushed will solve the problem, also check your constraints and make sure the bottom has safe area insets.Ritaritardando
I tried using hidebottombarwhenpushed but it didn't work with UISplitViewControllerHickok
E
20

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.

Earthling answered 17/8, 2021 at 7:38 Comment(5)
You are my lifesaver. Thank you so much!Tabatha
This worked for me on iOS 14.5Earplug
Working on iOS 15 as well. ThanksYeti
Working on iOS 16.1. Thank you!Rye
Not working in iOS 17 as of 12/2023Kratz

© 2022 - 2025 — McMap. All rights reserved.