This is what I'm trying to do...
I have one view controller that needs to dynamically display different subviews based on the presence of some data.
Here is a simple mockup. Each colored block represents a unique subview.
Sometimes the green block needs to be at the top, sometimes the green block won't display at all, sometimes the light blue block will be something different, etc.
Each subview has interactive elements, so I've been creating and adding them like so:
- Defining a new view controller
- Defining its view
- Calling
addChildViewController
anddidMoveToParentViewController
- Calling
addSubview
onmyNewViewController.view
- Using SnapKit to make auto layout constraints to position the view
I want to transition to UIStackView
because it seems a good support system for this view because all I need to do is stack its subviews. I'm seeing many conflicting constraint errors and unexpected view frames when trying to add subviews with their own inner auto layout constraints.
Question
Am I setting myself up for failure here by embedding the views of 4-6 view controllers in the view of one view controller?
Also, how do I give the added views properties like minimum heights or content sizes without seeing many breaking constraints with UIStackView
? (So they can stack, but one of them is say, 400 tall, and the other is 200 tall)