0

I'm trying to hide a UITabBarController and UINavigationController simultaneously when a button is touch. I found a very nice code snippet here How to hide uitabbarcontroller but I have problem when trying to hide and animate both UINavigationController and the tabbarcontroller. I also found a lot of examples on the internet when they hide the tabbar using self.tabBarController.tabBar.hidden = YES but that only hides the button items not the black bar at the bottom.

After playing a lot around I can get to make both animate correctly because I think that it's related to the hiding of the Navigation Controller which makes the size of the whole window to change on the fly.

-(IBAction)touchImage:(id)sender {

    if (isImageFullScreen) {

        isImageFullScreen = NO;

        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [UIView transitionWithView:self.view
                          duration:0.5
                           options:UIViewAnimationOptionCurveLinear
                        animations:^
         {
             hotelImageButton.frame = CGRectMake(0,20,320,92);
             [self showTabBar:self.tabBarController];
         }
                        completion:^(BOOL finished)
         {
         }];

    } else {

        isImageFullScreen = YES;

        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [UIView transitionWithView:self.view
                          duration:0.5
                           options:UIViewAnimationOptionCurveLinear
                        animations:^
         {
             hotelImageButton.frame = CGRectMake(0,0,320,480);
             [self hideTabBar:self.tabBarController];
         }
                        completion:^(BOOL finished)
         {                                  
         }];
    }

}

The hideTabBar and showTabBar methods are the ones from the other post I linked above.

I also tried some other combinations but I can't make it look good. Any ideas?

Thanks in advance.

Community
  • 1
  • 1
Chompas
  • 553
  • 8
  • 19

2 Answers2

5

I tried that code now and I see that the UITabBar show animation doesn't take place smoothly. I managed to make it smoother by adjusting the duration period for the tabbar showing animation to be lower.

[UIView setAnimationDuration:0.2];

Hopefully that works.

EDIT: Please try this code, it resizes the parent view to be bigger in 1 animation transaction in such a way that only the bars are hidden and the content is shown.

- (IBAction)TestButton1:(UIButton *)sender {

if(!isAnimating){
    if(isTabBarAndNavBarHidden){

        [UIView transitionWithView:self.view
                          duration:0.5
                           options:UIViewAnimationOptionTransitionNone
                        animations:^
         {
             isAnimating=YES;

             CGFloat statusBar_height=[[UIApplication sharedApplication] statusBarFrame].size.height;
             CGFloat screen_height=[UIScreen mainScreen].bounds.size.height;

             [self.tabBarController.view setFrame:CGRectMake(self.tabBarController.view.frame.origin.x, 0, self.tabBarController.view.frame.size.width, screen_height)];
             [self.navigationController.navigationBar setFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x, statusBar_height, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
         }
                        completion:^(BOOL finished)
         {
             isTabBarAndNavBarHidden=NO;
             isAnimating=NO;
         }];

    }else{

        [UIView transitionWithView:self.view
                          duration:0.5
                           options:UIViewAnimationOptionTransitionNone
                        animations:^
         {
             isAnimating=YES;

             CGFloat statusBar_height=[[UIApplication sharedApplication] statusBarFrame].size.height;
             CGFloat screen_height=[UIScreen mainScreen].bounds.size.height;

             [self.tabBarController.view setFrame:CGRectMake(self.tabBarController.view.frame.origin.x, statusBar_height-self.navigationController.navigationBar.frame.size.height, self.tabBarController.view.frame.size.width, screen_height+self.navigationController.navigationBar.frame.size.height+self.tabBarController.tabBar.frame.size.height-statusBar_height)];
             [self.navigationController.navigationBar setFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];


         }
                        completion:^(BOOL finished)
         {
             isTabBarAndNavBarHidden=YES;
             isAnimating=NO;
         }];

    }
}

}

Mati Bot
  • 797
  • 6
  • 13
  • But besides that, aren't you getting a strange animation? The bar moves weird. Like going all to the bottom then appearing half the way down and then animating. – Chompas Oct 29 '12 at 16:54
  • Nope, it works as expected for me. Does it work for you if you only hide the tabbar or the navbar? – Mati Bot Oct 29 '12 at 17:14
  • It works if I only hide the tabbar. The problem is when trying to hide both. – Chompas Oct 29 '12 at 17:17
  • try the code I attached to my answer and tell me if that works for you. – Mati Bot Oct 30 '12 at 16:46
  • Still some final touches but works a little more as intended. Thanks for your help. – Chompas Oct 31 '12 at 13:39
0

This code is for iPhone 4/4S.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.lastContentOffset > scrollView.contentOffset.y)
    {
          NSLog(@"Scrolling up");

        [UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{



            [self.tabBarController.tabBar setFrame:CGRectMake(0, 430, 320, 50)];
             [self.navigationController.navigationBar setFrame:CGRectMake(0, 20, self.navigationController.navigationBar.frame.size.width,self.navigationController.navigationBar.frame.size.height)];

             } completion:
           ^(BOOL finished) {

                [UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{


                      } completion:^(BOOL finished) {
                              //
                        }];

            }];

    }
    else if (self.lastContentOffset < scrollView.contentOffset.y)
    {
        [UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
               [self.navigationController.navigationBar setFrame:CGRectMake(0, -60, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
            [self.tabBarController.tabBar setFrame:CGRectMake(0, 480, 320, 50)];


        } completion:
         ^(BOOL finished) {

             [UIView animateWithDuration:.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

             } completion:^(BOOL finished) {

             }];

         }];



        NSLog(@"Scrolling Down");

    }

    self.lastContentOffset = scrollView.contentOffset.y;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tabBarController.tabBar setFrame:CGRectMake(0, 430, 320, 50)];
     [self.navigationController.navigationBar setFrame:CGRectMake(0, 20, self.navigationController.navigationBar.frame.size.width,self.navigationController.navigationBar.frame.size.height)];



    // Do any additional setup after loading the view.
}
floyddd
  • 71
  • 12