我有这个故事板:
TabBarController:Tab1> NavigationController> VC1>
// VC1.m
[self performSegueWithIdentifier:@"VC2" sender:self];
// VC2.m
[self performSegueWithIdentifier:@"VC3" sender:self];
我希望VC1和VC2之间的转换是淡入淡出动画,但VC2和VC3之间的转换是默认动画。
但是我必须做一个push segue而不是模态来保持UINavigationController的好处(除非我错过了什么)。我找到的所有解决方案都使用presentViewController
。
答案 0 :(得分:1)
尝试使用此CATransition
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
[navigationController.view.layer addAnimation:transition forKey:kCATransition];
isPush ? [navigationController pushViewController:viewController animated:NO] : [navigationController popViewControllerAnimated:NO];
答案 1 :(得分:0)
如果你坚持使用segue而不是我看到两种方式:
1)使用UIViewControllerAnimatedTransitioning协议并按照喜欢的方式自定义转换。
2)编写自定义UIStoryboardSegue
或者通过操纵控制器及其视图和框架来执行您自己的过渡和动画,如:
- (void)transitionToChildViewController:(UIViewController *)toViewController {
UIViewController *fromViewController = ([self.childViewControllers count] > 0 ? self.childViewControllers[0] : nil);
if (toViewController == fromViewController || ![self isViewLoaded]) {
return;
}
UIView *toView = toViewController.view;
[toView setTranslatesAutoresizingMaskIntoConstraints:YES];
toView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
toView.frame = self.privateContainerView.bounds;
[fromViewController willMoveToParentViewController:nil];
[self addChildViewController:toViewController];
[self.privateContainerView addSubview:toView];
[fromViewController.view removeFromSuperview];
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];
}
最后一种方法也许是最乏味的。