我正在处理的项目需要在两个视图控制器之间进行自定义转换。我通过覆盖以下方法设置并实现了 UIViewControllerTransitioningDelegate:
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
//Creation of animation
id<UIViewControllerAnimatedTransitioning> animationController;
MyAnimator *animator = [[MyAnimator alloc] init];
animator.appearing = YES;
animationController = animator;
return animator
}
我已经设置 MyAnimator 子类通过覆盖方法正确实现 UIViewControllerAnimatedTransitioning:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
//custom transition animation
}
我用来触发此动画转换的 segue 是以编程方式创建和调用的,例如:
UIStoryboardSegue *segue = [[UIStoryboardSegue alloc] initWithIdentifier:@"showCardDetail" source:self destination:vc];
[self prepareForSegue:segue sender:self];
[segue perform];
以编程方式创建 segue 的原因:我在不同的故事板中有 from(transition from) 和 to(transition to) 视图控制器。
问题/问题:我见过很多例子,都使用故事板segue处理自定义转换,例如:
[self performSegueWithIdentifier:@"storyboardSegue-id" sender:self]
我应该如何在上面以编程方式创建的 segue 方法中定义-perform以便发生自定义转换。