独自のトランジションを設計したい場合は、UIViewController へのカテゴリを作成し、アニメーションを自分で作成できます。すでに利用可能な基本的なアニメーションのみがあります。
これは、インターフェイスを実行する方法です。
*.h ファイル:
#import <UIKit/UIKit.h>
@interface UIViewController(Transitions)
- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction;
- (void) dismissViewControllerWithPushDirection:(NSString *) direction;
@end
*.m ファイル
#import "UIViewControllerWithTransitions.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIViewController(Transitions)
- (void) presentViewController:(UIViewController *)viewController withPushDirection: (NSString *) direction {
[CATransaction begin];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = direction;
transition.duration = 0.25f;
transition.fillMode = kCAFillModeForwards;
transition.removedOnCompletion = YES;
[[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[CATransaction setCompletionBlock: ^ {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
});
}];
[self presentViewController:viewController animated:NO completion:NULL];
[CATransaction commit];
}
- (void) dismissViewControllerWithPushDirection:(NSString *) direction {
[CATransaction begin];
CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = direction;
transition.duration = 0.25f;
transition.fillMode = kCAFillModeForwards;
transition.removedOnCompletion = YES;
[[UIApplication sharedApplication].keyWindow.layer addAnimation:transition forKey:@"transition"];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[CATransaction setCompletionBlock: ^ {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(transition.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^ {
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
});
}];
[self dismissViewControllerAnimated:NO completion:NULL];
[CATransaction commit];
}
@end
これはサンプル呼び出しです:
[self presentViewController: myVC withPushDirection:@"fromRight"];