在我的应用程序中,我试图切换视图,每个视图都是它们自己的 XIB,同时使用自定义动画来做到这一点。我制作了一个基本视图控制器作为父视图来保存所有代码,但我似乎无法让它工作。
我为我的应用程序和界面构建器中的所有视图控制器制作了一个 IBOutlet,我将插座连接到正确的控制器。每个控制器也加载正确的 XIB,所以这些都不是问题。问题是以下更改视图代码。
这是我的代码:
-(void)changeViews {
    CGRect frame = self.view.frame;
    frame.origin.x = CGRectGetMaxX(frame);
    theView4.view.frame = frame;
    [self.view addSubview:theView4.view];
    [self addChildViewController:theView4];
    [self transitionFromViewController:theView1 
                      toViewController:theView4 
                              duration:1 
                               options:UIViewAnimationOptionTransitionNone
                            animations: ^{
                                CGRect frame = self.view.frame;
                                theView4.view.frame = frame;
                                frame.origin.x -= frame.size.width;
                                self.view.frame = frame;
                            }
                            completion:completion:nil];
这是控制台崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Children view controllers <MyGameViewController: 0x1dd25210> and <Settings: 0x1dd249d0> must have a common parent view controller when calling -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
有谁知道如何解决这一问题?
谢谢!