添加自定义动画popToRootViewController [英] Adding custom animation to popToRootViewController

查看:313
本文介绍了添加自定义动画popToRootViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造流行到根视图控制器的自定义动画。我想创建在当前用户下滑的下方揭示了新的视图控制器,具有一些其他的事情,我会添加沿动画。我最大的问题是,我无法弄清楚如何将自定义动画添加到 popToRootViewController 。我创建了一个自定义动画,以presentViewController但无法弄清楚如何做同样的事情与 popToRootViewController 。任何帮助将是巨大的,通过我不一定需要使控制器滑下帮助的方式,我只是需要帮助使控制器显示任何动画。下面是我已经创建了$ P $自定义动画psenting一个视图控制器:

  FeedViewController *饲料= [[FeedViewController的alloc]初始化];
feed.transitioningDelegate =自我;
feed.modal presentationStyle = UIModal presentationCustom;
[自presentViewController:饲料动画:是完成:无];


解决方案

您必须实现UINavigationControllerDelegate协议方法:

   - (ID< UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController的*)navigationController
                                  animationControllerForOperation:(UINavigationControllerOperation)操作
                                               fromViewController:(UIViewController的*)fromVC
                                                 toViewController:(UIViewController的*)toVC

在这一点上,你应该能够在你的transitioningDelegate堵塞(返回!)

您可以返回如果你不想使用自定义控制器。例如,你可以使用

  {
   如果(操作== UINavigationControllerOperationPop)
   {
      返回MYTRANSITIONINGDELEGATE;
   }
}

请确保您设置navigationController的委托;)

I am trying to create a custom animation for pop to root view controller. I would Like to create an animation where the current user slides down and reveals the new view controller beneath, along with some other things I will add. My big problem is that I can't figure out how to add a custom animation to popToRootViewController. I have created a custom animation to presentViewController but can't figure out how to do the same thing with popToRootViewController. Any help would be great, by the way I do not necessarily need help with making the controller slide down, I just need help making the controller show with any animation. Here is how I have created a custom animation for presenting a view controller:

FeedViewController *feed = [[FeedViewController alloc] init];
feed.transitioningDelegate = self;
feed.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:feed animated:YES completion:nil]; 

解决方案

You have to implement the UINavigationControllerDelegate protocol method:

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                  animationControllerForOperation:(UINavigationControllerOperation)operation
                                               fromViewController:(UIViewController *)fromVC
                                                 toViewController:(UIViewController *)toVC

At that point you should be able to plug in your transitioningDelegate (return! )

You can return nil if you don't want to use your custom controller. For instance you could use

{
   if(operation==UINavigationControllerOperationPop)
   {
      return MYTRANSITIONINGDELEGATE;
   }
}

Make sure you set your navigationController's delegate ;)

这篇关于添加自定义动画popToRootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆