gpt4 book ai didi

ios - 在 ios 中添加 View Controller 作为 subview

转载 作者:行者123 更新时间:2023-12-01 17:22:34 24 4
gpt4 key购买 nike

嗨,我正在尝试添加 view controller作为 child view .然后删除这个 view controller形成父 View 。我为此目的使用以下代码。

 self.loginView = [self.storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
[self.view addSubview:self.loginView.view];

此代码适用于 iOS8但在 iOS7此代码不起作用,它显示了屏幕的一半。显示了一半登录。

这可能是什么解决方案?

最佳答案

添加自定义 UIView您要在其中添加和显示 subview Controller 的主视图(在 XIB 中)中的对象。让 contentView是该 View 的名称。使用以下代码添加 subview Controller :

self.loginView = [self.storyboard instantiateViewControllerWithIdentifier:@"LOGIN"];
[self addChildViewController:self.loginView];
[self.loginView.view setFrame:CGRectMake(0.0f, 0.0f, self.contentView.frame.size.width, self.contentView.frame.size.height)];
[self.contentView addSubview:self.loginView.view];
[self.loginView didMoveToParentViewController:self];

如果您不添加最后一行,您的 subview Controller 将不会收到事件。通过使用此代码,您可以同时在父 View Controller 和 subview Controller 中接收事件。

关于ios - 在 ios 中添加 View Controller 作为 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27222383/

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