0

カスタムトランジションを使用しようとしています。ビュー コントローラー 1 から 2 への「垂直方向のカバー」トランジションが必要であり、ビュー コントローラー 3 に移動するときにビュー コントローラー 2 (中央のもの) を再び下にスライドさせます。以下に示すストーリーボード:

http://i.stack.imgur.com/bJYXI.png

この投稿からリンクされているチュートリアルを使用しています。また、.m コードを回答で提供されているコードに置き換えました。

Xcode カスタム セグエ - Cover Vertical の反対 (上から下) - COMPLETE NEWBIE

UIViewController のサブクラスを作成し、FromTopReplaceSegue という名前を付けました。私の .h および .m コードを以下に示します。

.h

#import <UIKit/UIKit.h>

@interface FromTopReplaceSegue : UIViewController
@property(nonatomic, readonly) id sourceViewController;
@property(nonatomic, readonly) id destinationViewController;

@end

.m

#import "FromTopReplaceSegue.h"

@interface FromTopReplaceSegue ()

@end

@implementation FromTopReplaceSegue

-(void)perform{
    UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
    UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
    [sourceViewController.view addSubview:destinationViewController.view];
    [destinationViewController.view setFrame:sourceViewController.view.window.frame];
    [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)];
    [destinationViewController.view setAlpha:1.0];

    [UIView animateWithDuration:0.75
                          delay:0.0
                        options:UIViewAnimationOptionTransitionFlipFromTop
                     animations:^{
                         [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                         [destinationViewController.view setAlpha:1.0];
                     }
                     completion:^(BOOL finished){
                         [destinationViewController.view removeFromSuperview];
                         [sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
                     }];}

@end

シミュレーターを実行しようとすると、コントローラー ビュー 1 から 2 に簡単に移動できますが、カスタム セグエを使用してコントローラー ビュー 2 から 3 に移動しようとするとクラッシュします。

誰でも助けることができます。

よろしくお願いします!ここで苦戦!:)

4

1 に答える 1

5

私の iOS 時代から.h少し時間が経ちましたが、viewcontroller の代わりに seque クラスのサブクラスを定義すべきではありませんか? お気に入り

@interface FromTopReplaceSegue : UIStoryboardSegue

サブクラス化に関するいくつかの注意事項については、ドキュメントを読むこともできます...

于 2013-09-10T11:42:12.257 に答える