自定义transitionFromViewController抛出错误

时间:2013-04-30 19:24:12

标签: ios objective-c

我需要在我的导航控制器中创建一个方法,类似于 pushViewController:viewController animated:YES 方法,但我需要将80px添加到视图控制器的框架顶部,同时执行从左到右过渡。但是,下面的方法会抛出以下错误:

  

父视图控制器在调用时使用旧版包含    - [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];
                            }];
}

3 个答案:

答案 0 :(得分:3)

您是否正在调用UINavigationController上的transitionFromViewController? (self是UINavigationController的一个实例?)因为如果在UINavigationController上调用transitionFromViewController,就会出现此错误。 Apple doc说明了这种方法

  

仅用于通过自定义的实现来调用   容器视图控制器。如果覆盖此方法,则必须调用   超级实施

。有关详细信息,请查看http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html

答案 1 :(得分:3)

哇, 我也一直在努力争取这几个小时。

这是我发现的,它可能会帮助别人。

我没有从transitionFromViewController拨打UINavigationController,但是,我收到了同样奇怪的消息

*** 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:]'

我终于发现我的问题是我在容器UIViewController子类中重写了这个方法:

-(BOOL)shouldAutomaticallyForwardAppearanceMethods
{
    return NO;
}

通常默认为YES,除非您想自己处理(我受到了Apple WWDC2012 MediaNote示例代码的启发......)。

如果您希望transitionFromViewController有效,则shouldAutomaticallyForwardAppearanceMethods应返回YES。

答案 2 :(得分:0)

从Apple查阅本教程 Managing Appearance Updates for Children

您需要处理外观的方法会通知您自己。

[self.child beginAppearanceTransition: YES animated: animated];
//
[self.child endAppearanceTransition];