pizzafilms
pizzafilms

Reputation: 4019

How to change transition style for popToRootViewController?

I have a navigation-based app where I push several viewControllers (normal right to left) to create an event. When the user gets to the last screen and creates the event, I call...

[self.navigationController popToRootViewControllerAnimated:YES]; 

...to return to the first screen. This works okay, but when the transition animation is just a simple left to right.

Is there a way to change the transition style to be something other than left to right for just the popToRootViewController? I'd like it to look different than just going back to the previous screen.

Upvotes: 2

Views: 727

Answers (3)

KIDdAe
KIDdAe

Reputation: 2722

I guess instead of calling popToRootViewController you can do your own method (by subclassing UINavigationController, or doing a category or whatever you want)

and do something like that (the code will be different depending of where you will implement it, but here is the idea) :

UIViewController *rootVC = self.navigationController.topViewController;
[UIView animateWithDuration:1 animations:^{
    // Have fun doing what you want with the rootview
    [self.view addSubview:rootVC.view];
} completion:^(BOOL finished) {
    [self.navigationController popToRootViewControllerAnimated:NO];
}];

Upvotes: 0

spassas
spassas

Reputation: 4818

Supposing that we're talking about iOS 7+, you will need to implement UINavigationControllerDelegate protocol in your navigation controller. From there on, use navigationController:animationControllerForOperation:fromViewController:toViewController: to provide a UIViewControllerAnimatedTransitioning conforming object that will perform your custom animation. You can take a look at UINavigationControllerDelegate docs for more info.

Upvotes: 0

ZAZ
ZAZ

Reputation: 593

Hope it helps!

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

CATransition *transition = [CATransition animation];
[transition setType:kCATransitionFade];
[self.navigationController.view.layer addAnimation:transition forKey:@"someAnimation"];

[self.navigationController popViewControllerAnimated:YES];
[CATransaction commit];

Upvotes: 1

Related Questions