Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom transitionFromViewController throws error

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];
                            }];
}
like image 482
user987723 Avatar asked Feb 16 '23 16:02

user987723


2 Answers

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

like image 84
danypata Avatar answered Feb 27 '23 13:02

danypata


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 transitionFromViewControllerto work, then shouldAutomaticallyForwardAppearanceMethodsshould return YES.

like image 44
Vinzzz Avatar answered Feb 27 '23 13:02

Vinzzz