嗨,我正在尝试添加 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/