Search code examples
iosuiviewanimationtransition

Interactive Animated Transition between NavigationControllers


When presenting a new ViewController using the:

 UINavigtionController *nav = [[UINavigationController alloc] initWithRoot(myVC)]
 [self presentViewController:nav animated:YES completion:nil];

The UIViewControllerTransitionDelegate is never triggered since I am declaring this in myVC. My question is thus: how do I properly setup a interactive transition using the above initializiation?

EDIT:

I tried to follow the advice given below with no luck yet:

VC1.m :

LTFollowersListViewController *f = [LTFollowersListViewController new];
f.delegate = self;
LTNavigationController *nav = [[LTNavigationController alloc] initWithRootViewController:f];

[self presentViewController:nav animated:YES completion:nil];

VC2.h:

@interface LTFollowersListViewController : UIViewController <UIViewControllerTransitioningDelegate>
@property (nonatomic, strong) id<UIViewControllerTransitioningDelegate> delegate;

VC2.m:

@property (nonatomic, strong) CEPanAnimationController *animationController;
@property (nonatomic, strong) CEHorizontalSwipeInteractionController *interactionController;

in the viewDidLoad: {

self.delegate = self;
self.animationController = [[CEPanAnimationController alloc] init];
self.interactionController = [[CEHorizontalSwipeInteractionController alloc] init];
}

in the bottom of file: #pragma mark - UIViewControllerTransitionsingDelegate

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {
    NSLog(@"Reached the animation dismissal");

    // allow the interaction controller to wire-up its gesture recognisers
    [self.interactionController wireToViewController:self.navigationController forOperation:CEInteractionOperationDismiss];
    self.animationController.reverse = NO;
    return self.animationController;
}

- (id<UIViewControllerAnimatedTransitioning>)
animationControllerForDismissedController:(UIViewController *)dismissed {
    self.animationController.reverse = YES;
    return self.animationController;
}

- (id<UIViewControllerInteractiveTransitioning>)
interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator {
    NSLog(@"Reached the animation interaction");

    // provide the interaction controller, if an interactive transition is in progress
    return self.interactionController.interactionInProgress
    ? self.interactionController : nil;
}

Any suggestions as to what I am missing here? Thanks!


Solution

  • Did you miss

    .h file declare the delegate and protocol ViewController will implement

    @interface ViewController : UIViewController<UIViewControllerTransitioningDelegate>
    
    @property (nonatomic, strong) id<UIViewControllerTransitioningDelegate> delegate; 
    

    .m file Setting the delegate

    self.delegate = self;
    

    and also implement the delegate methods.