Can I create a UIContainerView programmatically?

僤鯓⒐⒋嵵緔 提交于 2020-01-01 02:17:50

问题


I'm trying to create a dynamic View flow that uses UIContainerViews to host UIViewControllers. The UIContainerViews (or UIViewControllers) 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)

回答1:


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];


来源:https://stackoverflow.com/questions/29694628/can-i-create-a-uicontainerview-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!