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 方法是我在上面链接的另一篇文章中的方法。

我也尝试了一些其他的组合,但我不能让它看起来很好。有任何想法吗?

提前致谢。

4

2 回答 2

5

我现在尝试了该代码,我发现 UITabBar 显示动画没有顺利进行。我设法通过将显示动画的选项卡栏的持续时间调整为较低来使其更平滑。

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

    }
}

}

于 2012-10-29T16:18:39.663 回答
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.
}
于 2014-09-17T11:31:19.490 回答