0

버튼이 눌릴 때 동시에 UITabBarController와 UINavigationController를 숨기려고합니다. 내가 여기에 아주 좋은 코드 조각을 발견 How to hide uitabbarcontroller하지만 숨기기 및 UINavigationController 및 tabbarcontroller 애니메이션하려고 할 때 문제가 있습니다. 나는 또한 그들이 self.tabBarController.tabBar.hidden = YES을 사용하여 tabbar를 숨길 때 인터넷에서 많은 예제를 발견했으나 하단의 검은 색 막대가 아닌 버튼 항목 만 숨 깁니다.애니메이션이있는 탐색 컨트롤러와 탭 막대 컨트롤러를 모두 표시하지 않습니다.

주위를 많이 놀고 난 후에는 전체 창 크기를 변경하는 탐색 컨트롤러 숨기기와 관련되어 있기 때문에 두 애니메이션을 올바르게 만들 수 있습니다.

-(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 쇼 애니메이션이 원활하게 수행되지 않는다는 것을 알았다. 애니메이션을 표시하는 탭바의 지속 기간을 낮춤으로써 더 부드럽게 만들 수있었습니다. 작동

[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

아니, 그것은 나를 위해 예상대로 작동합니다. 탭바 또는 탐색 바를 숨기는 경우에만 사용할 수 있습니까? –

+0

탭바 만 숨기면 작동합니다. 문제는 둘 다 숨기려고 할 때입니다. – Chompas

0

이 코드는 아이폰 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. 
} 
관련 문제