3

我有一个 ViewController 可以说ViewControllerA和一个 ViewController 可以说ViewControllerB

ViewControllerBViewControllerA通过使用自定义转换以模态方式呈现。

在 ViewControllerA 中:

-(void)buttonClicked...
{
  ViewControllerB * controller = [[ViewControllerB alloc] init];
  [controller setModalPresentationStyle:UIModalPresentationCustom];
  controller.transitioningDelegate = self;
  [self presentViewController:controller animated:YES completion:nil];
}

在 ViewControllerA -

#pragma mark - UIViewControllerTransitioningDelegate

- 

(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                      presentingController:(UIViewController *)presenting
                                                                          sourceController:(UIViewController *)source 
{

   FadeInWithPopAnimator* fadeInAnimator = [[FadeInWithPopAnimator alloc] init];
   return fadeInAnimator;
 }

我有一个名为的自定义 Animator 类FadeInWithPopAnimator,它实现了 transitionDuration 和 animationTransition 方法。

我想在呈现的 viewcontroller - 上为几个视图设置动画ViewControllerB,在过渡动画开始后 0.2 秒。

我已经在线阅读了文档,看起来使用 transitionCoordinator 是要走的路。但是我应该把代码放在哪里?

1) 在调用 presentViewController 时ViewControllerA

2)在动画师类?

3) 在视图中会出现ViewControllerA什么?

我已经尝试了几件事,但它没有给我结果,而且很难找到例子。

4

1 回答 1

2

呈现的视图控制器上的 TransitionCoordinator 将在视图控制器的动画开始后设置,因此在viewWillAppear呈现的视图控制器中。animateAlongsideTransition:completion:使用过渡协调器添加任何额外的动画。在您的 ViewControllerB 中:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear];

    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {

        // change any properties on your views

    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {


    }];
}
于 2016-08-24T10:44:29.570 回答