gpt4 book ai didi

ios - addChildViewController View 不显示

转载 作者:行者123 更新时间:2023-11-29 12:44:57 24 4
gpt4 key购买 nike

使用 Storyboard,我试图在当前 View 之上覆盖一个 UIViewController

在我的 FirstViewController 中,我导入了 SecondViewController.h,然后在 viewDidLoad 方法中运行以下命令

SecondViewController *overlay = [[SecondViewController alloc]init];
overlay.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[self addChildViewController:overlay];
[self.view addSubview:overlay.view];
[overlay didMoveToParentViewController:self];
[self.view bringSubviewToFront:overlay.view];

在我的 SecondViewController.h viewDidLoad 方法中,我有一个输出到 NSLog,当我运行应用程序时,它会显示在控制台中,但是第二个 View 没有显示在第一个 View 之上。所以 SecondViewController 被添加但没有显示。我错过了什么?

本质上,我希望 SecondViewController 具有透明背景,这样我就可以做一个显示信息的奇特警报消息,您仍然可以看到它后面的 FirstViewController

谢谢

最佳答案

首先设置secondViewController的标识符,使用简单代码:

secondViewController *overlay = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
overlay.view.frame = CGRectMake(100, 100, 100, 200);
[self.view addSubview:overlay.view];

在我的例子中,标识符与类名相同,即“secondViewController”。

关于ios - addChildViewController View 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23888417/

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