I need to create a method in my navigation controller similar to the pushViewController:viewController animated:YES method but i need to add 80px to the top of the frames of the view controllers whilst it does the left to right transition. However the method below is throwing the following error:
Parent view controller is using legacy containment in call to -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
- (void)transitionFrom:(UIViewController *)oldController To:(UIViewController *)newController
{
[self addChildViewController:newController];
//[self configureChild:newController];
[newController.view setFrame:CGRectMake(320, 80, oldController.view.frame.size.width, oldController.view.frame.size.height)];
[self transitionFromViewController:oldController
toViewController:newController
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[oldController.view setFrame:CGRectMake(-320, 80, oldController.view.frame.size.width, oldController.view.frame.size.height)];
[newController.view setFrame:CGRectMake(0, 80, newController.view.frame.size.width, newController.view.frame.size.height)];
}
completion:^(BOOL finished){
//[oldController willMoveToParentViewController:nil];
[oldController removeFromParentViewController];
[newController didMoveToParentViewController:self];
}];
}
Are you calling the transitionFromViewController
on a UINavigationController ? (self
is an instance of UINavigationController ?) Because you get this error if you call transitionFromViewController
on a UINavigationController. The Apple doc states that this method
is only intended to be called by an implementation of a custom container view controller. If you override this method, you must call super in your implementation
. For more details check http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html
Wow, I have been struggling a few hours with this one too.
Here's what I found out, it might help others.
I wasn't calling transitionFromViewController
from a UINavigationController
, but nevertheless, I got that same weird message
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Parent view controller is using legacy containment in call to
-[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
I finally found that my problem was that I had overriden this method in my container UIViewController subclass :
-(BOOL)shouldAutomaticallyForwardAppearanceMethods
{
return NO;
}
which normally defaults to YES, unless you want to handle it yourself (I had been inspired by Apple WWDC2012 MediaNote sample code...).
If you want transitionFromViewController
to work, then shouldAutomaticallyForwardAppearanceMethods
should return YES.
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