ソース シーンにあるボタンを使用して、目的のシーンをセグエしたいと考えています。また、ビューコントローラー間の遷移アニメーションを制御したいと思います(2つのビューを右から左にアニメーション化したい)。セグエを置き換えることでそれを行うことは可能ですか? セグエの置き換えとセグエのプッシュの両方を試しましたが、セグエは発生していません。ありがとう!
7917 次
1 に答える
8
置換はマスター詳細コントローラーで使用でき、プッシュセグエはナビゲーションコントローラーでのみ使用できるように見えるため、置換セグエとプッシュセグエは誤解を招くことがわかりました。この場合、代わりにカスタマイズ セグエを実装する必要がありました。UIStoryboardSegue をサブクラス化し、Perform Segue をオーバーライドする必要があります。
ここに私のコードの例があります:
-(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/
于 2012-03-01T00:00:55.253 に答える