我可以通过编程方式创建UIContainerView吗? [英] Can I create a UIContainerView programmatically?
问题描述
我正在尝试创建一个使用UIContainerView
托管UIViewController
的动态视图流.需要将UIContainerView
(或UIViewController
s)以编程方式添加到UIView
中,以允许多个并排.
我一直在寻找,但是找不到任何可用于创建我的UIContainerView
的构造函数.
是否有一种简单的方法来执行此操作,或者是否违反了创建可重用视图的常规准则?
总而言之,我想实现以下目标:
var containerView = UIContainerView()
containerView.add(myViewController)
UIContainerView
只是一种将viewController添加为另一个子视图并设置其边界的视觉方法.
您可以通过编程方式执行此操作,方法是将第二个viewController添加为第一个viewController的子级,获取第二个viewController的视图并将其放置在第一个viewController的某个位置.
像这样的东西
childVC = [[SomeViewController alloc] init];
[self addChildViewController:childVC];
[self.view addSubview:childVC.view];
[childVC didMoveToParentViewController:self];
I'm trying to create a dynamic view flow that uses UIContainerView
s to host UIViewController
s. The UIContainerView
s (or UIViewController
s) need to be programmatically added to the UIView
to allow multiple side by side.
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
is just a visual way to add a viewController as a child of another and setting its bounds.
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.
Something like this;
childVC = [[SomeViewController alloc] init];
[self addChildViewController:childVC];
[self.view addSubview:childVC.view];
[childVC didMoveToParentViewController:self];
这篇关于我可以通过编程方式创建UIContainerView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!