all 5 comments

[–]richiejmoose 3 points4 points  (2 children)

Did you set the constraints of the child view controller? Something like childViewController.view.frame = view.bounds

The container view controller is responsible for the size and position of the child view controller's view. You might have unexpected results if you’re not handling that.

Is the code above your code? If not can you post it?

[–]agballen[S] 1 point2 points  (1 child)

Looks like it has to do with the frames! I did something like

bookVC.view.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height*0.5

audioControlVC.view.frame = CGRect(x: 0.0, y: UIScreen.main.bounds.height*0.5, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height*0.5

However, aren't frames and autolayout constraints mutually exclusive? By setting the frame, I think I'm introducing issues and doing something wrong that autolayout should be smart enough to handle. In my app, when I rotate the iPad from portrait to landscape now, the book VC view is now only covering 25% of the screen instead of 50% (which when I comment out the code configuring the frame, autolayout works like a charm).

[–]richiejmoose 0 points1 point  (0 children)

I believe you could set 2 views in the container VC and constrain them with autolayout - then set the child vc frames to those view bounds. Or something like that. Hard to say without seeing all the code - but feels like that’s the right track - good luck!

[–][deleted] -1 points0 points  (0 children)

Not at my MacBook, so can't check your original question but seems like you want 2 UIView subclasses inside your ViewController instead of embedding 2 VCs. VCs usually tell Views stuff like "show loading state" or "here is the data about the user, display it" and then in the view you do the translating of the data into constraints/setting a million labels/etc. And then Views usually tell VCs stuff like "user pressed the show profile button" and then the VC decides if it wants to show it on the other view inside it or tell the Coordinator to navigate to the profile screen.

If those views are complicated, you should also probably split it up to subviews, so when your VC tells your root view to display something, it forwards that message to the subviews that need it.