5

I have a ViewController lets say ViewControllerA and a ViewController lets say ViewControllerB.

ViewControllerB is modally presented from ViewControllerA using a custom transition.

In ViewControllerA:

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

In ViewControllerA -

#pragma mark - UIViewControllerTransitioningDelegate

- 

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

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

I have an custom Animator class called FadeInWithPopAnimator which implements the transitionDuration and animationTransition methods.

I want to animate a couple of views on the presented viewcontroller - ViewControllerB, 0.2 seconds after the transition animation starts.

I have read the docs online and it looks like using a transitionCoordinator is the way to go. But where should I put the code ?

1) While calling the presentViewController in ViewControllerA ?

2) In the Animator class ?

3) In viewWillAppear of ViewControllerA?

I have tried a couple of things but it is not giving me results and examples are hard to find.

Mahendra
  • 8,448
  • 3
  • 33
  • 56
newbie
  • 1,049
  • 5
  • 15
  • 29

1 Answers1

5

TransitionCoordinator on the presented view controller will be set after a view controller's animation has started, so in viewWillAppear of the presented view controller. Add any extra animations using animateAlongsideTransition:completion: on the transition coordinator. In your case in 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) {


    }];
}
sash
  • 8,423
  • 5
  • 63
  • 74