Showing/hiding navigation bar with smooth animation

前端 未结 3 1477
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 09:38

I have a navigation based app. The first view (rootcontroller) starts with three large buttons only. No navigationbar. From there, everything else is tableviews and have

3条回答
  •  天命终不由人
    2020-12-23 10:01

    This nifty bit of code animates the navigation bar hiding with no UI issues:

    [navigationController setNavigationBarHidden: YES animated:YES]

    But...

    1. Use the self.navigationController.navigationBarHidden property for checks in the code instead of the self.navigationController.navigationBar.hidden property. This will save you a lot of pain from unexpected UI positioning problems.
    2. Take care to place this method in - (void)viewWillAppear:(BOOL)animated or later in the view lifecycle. This is recommended because if you do it in - (void)viewDidLoad for instance, you will get an ugly black rectangular view during animations from a view which displays its navigation bar to a view which doesn't! For example, if your home view has its navigation bar hidden but all its children have the navigation bar shown, when you pop to home view, the animation will show a black bar in place of the navigation bar until the animation completes

提交回复
热议问题