UIStroryBoard 当您推送视图控制器或 segues 时,它不会让您自定义太多。我最终做的是重写 perform 方法并使用 QuartzCore Animations 来自定义我们的过渡。我继承了 UIStoryBoardSegue 并覆盖了 perform 函数。
下面为 Push 或 Pop 定制,然后为 Segues 定制。(对于 segues,请记住将类更改为 IB 中的自定义类)。
要从普通的 pop 或 push(这确实交叉淡入淡出动画,请根据您的调整):
#import <QuartzCore/QuartzCore.h>
- (IBAction)launch1990:(id)sender {
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"1990"];
[self.navigationController pushViewController:vc animated:NO];
}
从 segue 做到这一点:
//ZHCustomSegue.h
#import <Foundation/Foundation.h>
@interface ZHCustomSegue : UIStoryboardSegue
@end
// ZHCustomSegue.m
#import "ZHCustomSegue.h"
#import "QuartzCore/QuartzCore.h"
@implementation ZHCustomSegue
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}
@end