I have an UINavigationController. I made VC1 the rootViewController and programatically load VC2 from VC1 and then have the custom animation to go from VC1 to VC2. Standard. Everything is fine and good.
Now, I would like to have a custom animation between the two like so:
In sum, VC1 slides out of view while VC2 is beneath it. Just like a stack of paper where you slide away the first sheet (VC1) and thus reveal the sheet beneath (VC2).
So what I tried is the following code which is called from VC1 in order to get to VC2. But there are problems with it:
MyVC2 *vctwo = [[[MyVC2 alloc] init] autorelease];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[[self navigationController] pushViewController:vctwo animated:YES];
The problems are the following:
Any suggestions why I am not getting the expected results would be very much appreciated. Sorry if this is obvious, but I am trying this for hours now and got really frustrated.
I think you should use [[self navigationController] pushViewController:vctwo animated:NO];
rather than animated:YES
.
I suppose the only way to do this is to forget UINavigationController and come up with my own mechanism to handle everything:
This blog explains how...
So if you wanted to custom animations between VCs, do not use UINavigationController. Here is sample code to swap between two VCs as described above:
-(void)slideDoorOpenTo:(UIViewController *)aController duration:(float)aDuration {
[aController viewWillAppear:YES];
[activeController viewWillDisappear:YES];
//aController.view.alpha = 0.0f;
[self.view insertSubview:aController.view belowSubview:activeController.view]; // so that it is below activeController
[aController viewDidAppear:YES];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:aDuration];
aController.view.transform = CGAffineTransformMakeTranslation(0,0);
activeController.view.transform = CGAffineTransformMakeTranslation(-320,0);
[UIView commitAnimations];
[self performSelector:@selector(animationDone:) withObject:aController afterDelay:aDuration];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With