0

我試圖隱藏UITabBarController和UINavigationController同時觸摸一個按鈕。我在這裏找到了一個非常漂亮的代碼片段How to hide uitabbarcontroller,但是我試圖隱藏和動畫UINavigationController和tabbarcontroller時遇到了問題。當他們使用self.tabBarController.tabBar.hidden = YES隱藏標籤欄時,我還在互聯網上找到了很多示例,但只隱藏按鈕項目而不是底部的黑色欄。隱藏導航控制器和標籤欄控制器與動畫

在玩過很多遊戲後,我可以正確設置動畫,因爲我認爲它與導航控制器的隱藏有關,這使得整個窗口的大小可以隨時更改。

-(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) 
     {         
     }]; 
    } 

}

的hideTabBar和showTabBar方法是從其他文章中,我上面鏈接的人。

我也嘗試了一些其他的組合,但我不能讓它看起來不錯。有任何想法嗎?

在此先感謝。

回答

5

我現在試過這個代碼,我發現UITabBar顯示動畫不能順利進行。 我通過調整顯示動畫效果較低的tabbar的持續時間來設法讓它更平滑。

[UIView setAnimationDuration:0.2];

希望工程。

編輯: 請嘗試此代碼,它將調整父視圖的大小,使其在1個動畫事務中變得更大,以便只隱藏條形圖並顯示內容。

- (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; 
     }]; 

    } 
} 

}

+0

但除此之外,你是不是得到一個奇怪的動畫?酒吧移動怪異。就像一切盡在底部,然後出現一半,然後進行動畫製作。 – Chompas

+0

不,它對我的​​預期效果。如果您只隱藏TabBar或導航欄,它是否適用於您? –

+0

它工作,如果我只隱藏標籤欄。問題是當試圖隱藏兩者。 – Chompas

0

該代碼可用於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. 
} 
相關問題