问题
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