2012-02-27 5 views
4

ソースシーンに存在するボタンを使ってデスティネーションシーンを分割したいと思います。私はviewcontroller(私は右から左に2つのビューをアニメーション化したい)の間のトランジションアニメーションのコントロールを持っていると思います。それは、置換のsegueを通じてそうすることは可能ですか?私は、セグーとプッシュセグを交換しようとしますが、セグーはそこに進むべきではありません。ありがとう!どのようにストーリーボードのUIButtonからカスタムセグ(モーダルセグ)を実行しますか

答えて

8

置き換えがマスターコントローラとナビゲーションコントローラのプッシュセグだけで使用できるように見えるため、segueとpush segueの置き換えが誤解を招くことがありました。この場合、代わりにカスタムセグを実装する必要がありました。 UIStoryboardSegueをサブクラス化し、実行セグをオーバーライドする必要があります。ここで

は、例えば私のコードのである:

-(void)perform{ 
    UIView *sourceView = [[self sourceViewController] view]; 
    UIView *destinationView = [[self destinationViewController] view];  

    UIImageView *sourceImageView; 
    sourceImageView = [[UIImageView alloc] 
         initWithImage:[sourceView pw_imageSnapshot]]; 

    // force the destination to be in landscape before screenshot 
    destinationView.frame = CGRectMake(0, 0, 1024, 748); 
    CGRect originalFrame = destinationView.frame; 
    CGRect offsetFrame = CGRectOffset(originalFrame, originalFrame.size.width, 0); 


    UIImageView *destinationImageView; 
    destinationImageView = [[UIImageView alloc] 
          initWithImage:[destinationView pw_imageSnapshot]]; 

    destinationImageView.frame = offsetFrame; 
    [self.sourceViewController presentModalViewController:self.destinationViewController animated:NO]; 

    [destinationView addSubview:sourceImageView];       
    [destinationView addSubview:destinationImageView]; 

    void (^animations)(void) =^{          
     [destinationImageView setFrame:originalFrame]; 

    }; 

    void (^completion)(BOOL) = ^(BOOL finished) {      
     if (finished) { 

      [sourceImageView removeFromSuperview]; 
      [destinationImageView removeFromSuperview]; 

     } 
    }; 

    [UIView animateWithDuration:kAnimationDuration delay:.0 options:UIViewAnimationOptionCurveEaseOut animations:animations completion:completion]; 
} 

主な考え方は、送信元と送信先のシーンのスクリーンショットビューを作成することです。それらをデスティネーションシーンビューに追加し、それらの2つのビューのアニメーションを制御し、sourceviewControllerのpresentModalViewController関数を呼び出し、アニメーションの終了時に2つのスクリーンショットビューを削除します。

このリンクのCh15でスクリーンショットユーティリティ機能を実装する例があります。http://learnipadprogramming.com/source-code/

関連する問題