4

i have a view controllers in a tab bar controller with constraints to bottom safe area, but one of them i must hide tab bar i use this self.tabBarController?.tabBar.isHidden = true this increase the safe area

But if i need to move to another i show back tab bar self.tabBarController?.tabBar.isHidden = false But safe area don't decrease by itself, making view contents behind tab bar

To make it clear i put a red view pinned to bottom safe area, next i go to view and hide tab bar enter image description here

this is when it come back to this view and show tab bar again, safe area increased below tab bar, that's why red square are more below enter image description here

  • are you using safeAreaInsets ? Those are just inset values it is best to use `safeAreaLayoutGuide`. Use the anchors – user1046037 Mar 08 '18 at 09:54
  • If you want to hide the tab bar when pushing another view controller onto the navigation controller (e.g. showing details of a particular item) you may set nextVC.hidesBottomBarWhenPushed = true before pushing the VC and the job will be done automatically without breaking the safe area configuration. – Rodrigo Guimarães Aug 29 '18 at 18:11

1 Answers1

1

It appears to be a bug in iOS. SafeArea doesn't change to account for tabBar, after hiding / showing it.

You can work around it by anchoring your view to superview and adjusting for tabBar manually. For example, if you want to anchor a tableView to a tabBar it would look like this

    if let tabBar = tabBarController?.tabBar {
        tabBar.isHidden = true
        tableViewBottomConstraint.constant = tabBar.frame.height
    }
Senõr Ganso
  • 1,694
  • 16
  • 23