検証環境
- XCode8.3.3
- iOS10.3.1
hidesBottomBarWhenPushed
UITabBarController
の中にUINavigationController
を持っていて下層に下っていくとする。
このとき、2階層目以降はタブを表示したくない場合、pushされるviewControllerのhidesBottomBarWhenPushed
をtrueにするとタブが隠された状態でpushされる。
viewController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(viewController, animated: true)
3階層目以降の挙動
ただタブを隠すだけなら上記で良いが、仮に3階層目以降でタブを表示したい場合(そんな場合があるかは置いておいて)の挙動が気になったので軽く検証してみた。
最前面のviewControllerがhidesBottomBarWhenPushed=true
の(=タブが表示されていない)状態で、さらにpushした場合の挙動を試したところ、以下の結果だった。
hidesBottomBarWhenPushed | tabBar |
---|---|
指定なし(false) | 表示されない |
false | 表示されない |
true | 表示されない |
つまり挙動としては既にタブが表示されていない場合は、hidesBottomBarWhenPushed
の値に関わらずタブが表示されない。
もう少し調べて見ると以下のstackoverflowが見つかった。
https://stackoverflow.com/questions/5641465/hidesbottombarwhenpushed-no-not-working
If YES, the bottom bar remains hidden until the view controller is popped from the stack.
とのことらしいので、スタックされているviewControllerの中にhidesBottomBarWhenPushed=true
のものがあると表示されないという事らしい。
ただ、
This is what the documentation for hidesBottomBarWhenPushed says
って書いてるけど見つけられなかった。。