我可以以编程方式创建UIContainerView吗? [英] Can I create a UIContainerView programatically?

查看:118
本文介绍了我可以以编程方式创建UIContainerView吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用UIContainerViews来托管UIViewControllers的动态View流。需要以编程方式将UIContainerViews(或UIViewControllers)添加到UIView中以允许多个并排。

I'm trying to create a dynamic View flow that uses UIContainerViews to host UIViewControllers. The UIContainerViews (or UIViewControllers) need to be programatically added to the UIView to allow multiple side by side.

我一直在寻找,但找不到任何构造函数我可以用来创建我的UIContainerView。

I've been looking around, but can't find any constructors I can use to create my UIContainerView.

有没有一种简单的方法可以做到这一点,还是违反了创建可重用视图的正常指导原则?

Is there a simple way to do this or is it against normal guidelines for creating reusable views?

总之,我希望实现这样的目标:

To sum up, I want to achieve something like this:

var containerView = UIContainerView()
containerView.add(myViewController)


推荐答案

A UIContainerView 只是一种将viewController作为另一个子节点添加并设置其边界的可视方式。

A UIContainerView is just a visual way to add a viewController as a child of another and setting its bounds.

你可以做这是以编程方式添加第二个viewController作为第一个的子节点,取第二个视图并将其放在第一个视图的某个位置。

You can do this programatically by adding the second viewController as a child of the first, taking the second's view and placing it somewhere on the first's view.

这样的东西;

childVC = [[SomeViewController alloc] init];

[self addChildViewController:childVC];

[self.view addSubview:childVC.view];

[childVC didMoveToParentViewController:self];

这篇关于我可以以编程方式创建UIContainerView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆