0

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!

trdavidson
  • 1,051
  • 12
  • 25
  • did you set the VC transition delegate? no matter what VC subclass if you call present VC method on a VC with a transition delegate it should let you handle all the animated transition business. you still need to implement the delegate methods tho. – JackyJohnson Dec 05 '14 at 01:24
  • @believesInSanta - that might be it! let me check and report back – trdavidson Dec 05 '14 at 01:31
  • @believesInSanta No luck unfortunately, I provided more code to clarify my current scheme. – trdavidson Dec 05 '14 at 02:14
  • well, first off, you're not supposed to present a navigation controller in the first place, that has implications on the transition as a navigation controller doesn't have a root view by itself - it uses its primary child view controller's root view instead, it literally just controls the navigation between its children view controllers - secondly, UIViewController should have a transitionDelegate property - use that, it's not just the delegate property, then your delegate calls should fire. how you are initiating the presented view controller shouldn't matter. – JackyJohnson Dec 05 '14 at 07:46
  • @believesInSanta - I also tried to set self.transitioningDelegate =self in the viewDidLoad but nothing happens. I am confused, since I would think that since I set the root of the NC to be myVC, NC should recognize myVC as its primary child VC and thus use its transitionDelegate. Am I not setting the delegate property correctly you think? – trdavidson Dec 05 '14 at 16:25
  • the point of using NCs is to have a stack of VCs that you can just pop and push onto literally to abstract your view navigation. NCs are not even VCs in the sense they just provide that stack behavior and not much else, so they make for ideal transition delegates. to clarify, whenever a VC is presented it asks for a transition coordinator and context from the transition delegate. but in your case, you are indirectly presenting a VC thru an NC so you can try [navigationController.rootViewController setTransitionDelegate:self]; but even if you make it work it'll end up looking pretty ugly IMO. – JackyJohnson Dec 05 '14 at 20:51
  • if you want to use an NC you should make it the primary controller and make it the transition delegate for each of its child VCs. otherwise like i said earlier to make a VC present an NC with a custom transition, you need to set the NC's root VC's transition delegate to your NC's presenting VC. hope that makes sense. – JackyJohnson Dec 05 '14 at 21:00
  • That makes a lot of sense, apologies for the late reply. I believe some restructering is in place on my end - Thanks! – trdavidson Dec 06 '14 at 20:15
  • You're welcome. I'm glad it made sense :P – JackyJohnson Dec 07 '14 at 10:43

1 Answers1

0

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.

Zigii Wong
  • 7,766
  • 8
  • 51
  • 79
  • @Wongziglii - that might be it! Let me check if that does the trick, will report back – trdavidson Dec 05 '14 at 01:30
  • @Wongziglii still no luck unfortunately, posted more code to clarify situation. – trdavidson Dec 05 '14 at 02:13
  • No errors - it just seems that the code is never called upon in the first place. I'm sure there is minor thing here that I'm missing but it's driving me crazy – trdavidson Dec 05 '14 at 02:24
  • remove `f.delegate = self;` and try. – Zigii Wong Dec 05 '14 at 03:14
  • Nothing happening..what is weird, is that when I present the VC directly, without using the initWithRoot method everything works fine. The problem is that I really do need the initWithRoot to setup my navBar correctly. – trdavidson Dec 05 '14 at 03:38