2012-08-17 3 views
7

UIViewController의 transitionFromViewController : toViewController : duration 메서드를 사용하지만 사용자 정의 애니메이션을 사용하려고합니다. transitionFromViewController : toViewController : duration을 사용하는 UIViewController 사이의 사용자 정의 애니메이션

I 사용자 지정 컨테이너의 UIViewController 어린이로 추가 다음과 같은 두 가지 뷰 컨트롤러가 있습니다

  1. firstController - 이것은
의 UIViewController의 서브 클래스입니다 - 이것은 UITabBarController가의 인스턴스
  • secondController입니다

    다음 코드는 예상대로 작동합니다.

    [self transitionFromViewController:firstController 
            toViewController:secondController 
              duration:2           
              options:UIViewAnimationOptionTransitionFlipFromLeft 
             animations:^(void){} 
             completion:^(BOOL finished){}]; 
    

    그러나 맞춤형 애니메이션을 만들고 싶습니다. 여기서 firstController은 왼쪽으로 이동하고 오른쪽에서 슬라이드하는 secondController으로 바뀌며 UINavigationControllers가 밀어 넣기 및 팝하는 방법과 비슷합니다. optionsUIViewAnimationOptionTransitionNone으로 변경 한 후 animations 블록에서 맞춤 애니메이션을 구현하려했지만 전혀 성공하지 못했습니다. firstController은 애니메이션없이 즉시 secondController으로 바뀝니다.

    정말 도움이됩니다.

    고맙습니다.

  • 답변

    15

    이것은 실제로 실제로 쉽습니다. 웬일인지 나는 secondController의 시야가 firstController의 것의 뒤/아래 일 것이라고 생각했다. 나는 firstController의보기를 움직이기 위해 노력했을뿐입니다. 이것은 물론 잘못되었습니다. 즉시 transitionFromViewController:toViewController:duration라고 부르면 secondController 님의 시연은 firstController 님의 전망에 올리게됩니다. 다음 코드가 작동합니다.

    CGFloat width = self.view.frame.size.width; 
    CGFloat height = self.view.frame.size.height; 
    
    secondController.view.frame = CGRectMake(width, 0, width, height); 
    
    [self transitionFromViewController:firstController 
        toViewController:secondController 
        duration:0.4 
        options:UIViewAnimationOptionTransitionNone 
        animations:^(void) { 
         firstController.view.frame = CGRectMake(0 - width, 0, width, height); 
         secondController.view.frame = CGRectMake(0, 0, width, height); 
        } 
        completion:^(BOOL finished){ 
         [secondController didMoveToParentViewController:self]; 
        } 
    ]; 
    
    +6

    [secondController didMoveToParentViewController : self]를 호출해야합니다. 완료 핸들러에서 너무 : – banDedo

    +1

    @banDedo 나는 그 코드를 업데이트했다. 그 점을 지적 해 주셔서 감사합니다. 그것을 필요로했다! –

    +0

    banDedo & Shaun F. 제안 및 수정 해 주셔서 감사합니다. – Simple99

    관련 문제