gpt4 book ai didi

ios - subview Controller 必须有一个共同的父 View Controller ?

转载 作者:可可西里 更新时间:2023-11-01 05:38:17 25 4
gpt4 key购买 nike

在我的应用程序中,我试图在使用自定义动画时切换 View ,每个 View 都是它们自己的 XIB。我制作了一个基本 View Controller 作为父 View 来保存所有代码,但我似乎无法让它工作。

我为我的应用程序和界面生成器中的所有 View Controller 制作了一个 IBOutlet,我将 socket 连接到适当的 Controller 。每个 Controller 也加载正确的 XIB,所以这些都不是问题。问题是以下更改 View 代码。

这是我的代码:

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

有人知道如何解决这个问题吗?

谢谢!

最佳答案

你可以使用这个:

When you use addChildViewController: to add the child view controller to the surrounding one. You also have to notify the child controller by didMoveToViewController: that it has been put into another controller. You can also use transitionFromViewController:toViewController: to exchange one view controller for another, optionally giving an animation.

这取自 here (我建议您完整阅读已接受的答案)。

长话短说,您还需要告知它确实已移入该父 View Controller 。

关于ios - subview Controller 必须有一个共同的父 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10190577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com