Saturday, June 8, 2013

UINavigationController setNavigationBarHidden animated example in Objective C (iOS).


UINavigationController setNavigationBarHidden animated

Sets whether the navigation bar is hidden.

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated

Parameters
hidden
Specify YES to hide the navigation bar or NO to show it.
animated
Specify YES if you want to animate the change in visibility or NO if you want the navigation bar to appear immediately.

Discussion of [UINavigationController setNavigationBarHidden animated]
For animated transitions, the duration of the animation is specified by the value in the UINavigationControllerHideShowBarDuration constant.

UINavigationController setNavigationBarHidden animated example.
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

Example of [UINavigationController setNavigationBarHidden animated].
- (void) viewWillDisappear:(BOOL)animated
{
    if (self.navigationController.topViewController != self)
    {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }

    [super viewWillDisappear:animated];
}

UINavigationController setNavigationBarHidden animated example.
For the UINavigationController:

[UINavigationBar beginAnimations:@"NavBarFade" context:nil];
self.navigationController.navigationBar.alpha = 1;
[self.navigationController setNavigationBarHidden:YES animated:NO]; //Animated must be NO!
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UINavigationBar setAnimationDuration:1.5];
self.navigationController.navigationBar.alpha = 0;
[UINavigationBar commitAnimations];
For the UITabBarController:

[UITabBar beginAnimations:@"TabBarFade" context:nil];
self.tabBarController.tabBar.alpha = 1;
[self.tabBarController.tabBar setHidden:YES];
[UITabBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UITabBar setAnimationDuration:1.5];
self.tabBarController.navigationBar.alpha = 0;
[UITabBar commitAnimations];

End of UINavigationController setNavigationBarHidden animated example article.