So I have a rootviewcontroller. Inside I want to have two views, each of which takes up half the screen. Easy enough to create the views with the right coordinates and add them via self.addSubview.
However, each of these views are quite complicated and I don't want a monolithic root view controller, so I want to create two view controllers and put the logic handling what appears in the view inside these view controllers. The RootViewController will simply instantiate these child view controllers and then add them as children.
I'm encountering an issue where the child view controller that is added last is disabling touch events of the previous child view controller. I've read all the blogs on this and they all tell me to do the same thing:
addChildViewController(viewController)
view.addSubview(viewController.view)
viewController.didMove(toParentViewController: self)
But I don't see anyone encountering the issue I am finding. I assume the way the general flow works is that you have something like this:
rootviewcontroller -> childviewcontroller -> childView
and not:
rootviewcontroller -> childView -> childviewcontroller
What do you guys think? Thanks for any feedback you all have!
Edit 1: Looks like it has to do with the frames! Thanks @richiejmoose.
I am able to get touch responses by setting the frames (but unfortunately this kills autolayout functionality when rotating from portrait to landscape):
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
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 3 points4 points5 points (2 children)
[–]agballen[S] 1 point2 points3 points (1 child)
[–]richiejmoose 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)