popToRootViewController forward animation

1k views Asked by At

In my library I have a loading view which pops to a input view. When the user is done with the input view it should go back to the loading view to do some magic again and when done it should show up a third view.

Now, from a usability view I don't want to "slide back" to the loading view, neither do I want to allocate a new loading view when I already have one in memory.

Is there some way I can popToRootViewController while sliding the view forwards? (Yes, I remove the back button in the loading view)..

2

There are 2 answers

0
mackross On BEST ANSWER

Alright here goes - perhaps try using something like this

// This goes in whatever view controller you want to pop with
- (void)popToRootWithForwardAnimation
{
    NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease]
    UIViewController * rootViewController = [viewControllers objectAtIndex:0]
    [viewControllers removeObjectAtIndex:0]; // try using with and without this line?
    [viewControllers addObject:rootViewController];

    [self.navigationController setViewControllers:viewControllers animated:YES];
}

// This goes in the root view controller
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated]
    NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease]
    if ([viewControllers count] > 1)
    {
        [viewControllers removeAllObjects];
        [viewControllers addObject:self];

        [self.navigationController setViewControllers:viewControllers animated:NO];
    }

    … 
    …
}
2
dbgrman On

Hmm, I'd say a better approach would be to flip the view in a modal fashion rather than push/pop in a navigation stack. So you would want to do in the input view where you are pushing next view controller:

MagicViewController *magicVC = [[MagicViewController alloc] init];
magicVC.setModalTransitionStyle  = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:magicVC animated:true];

Then when the Magic View controller is done doing its magic, just do at that point (where you otherwise pop):

[self dismissModalViewControllerAnimated:true];

This would be much more cooler than doing simple navigation.

See modal view controllers guide.