2012-08-17 4 views
7

UIViewControllerのtransitionFromViewController:toViewController:durationメソッドを使用していますが、カスタムアニメーションを使用しようとしています。 transitionFromViewController:toViewController:durationを使用するUIViewController間のカスタムアニメーション

IカスタムコンテナのUIViewControllerに子として追加された次の2つのビューコントローラがあります。

  1. firstController - これは
のUIViewControllerのサブクラスである - これはUITabBarControllerのインスタンス
  • secondControllerです

    次のコードは正常に動作します。

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

    しかし、ここではfirstControllerが左側にスライドし、が、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

    関連する問題