Note to googlers, this Q-A is now six years out of date!
As Micky below and others mention, this is now done on an everyday basis with Containers in iOS.
I have a ViewController which controls many subviews. When I click one of the buttons I initialize another viewcontroller and show it's view as the subview of this view. However the subview exceeds the bounds of the frame for subview and infact fills the entire screen.
What could be wrong? I presume the problem is that UIViewController's view has a frame (0,0,320,460) and hence fills the entire screen (though it receive's touch events only when touched within the subview frame bounds). How can I resize the frame to fit as subview.
In short, I need help adding a viewcontroller's view as a subview to another viewcontroller's view.
Thanks!
You may use PopupController for the same one the SDK which shows UIViewController as subview You may check PopupController
Here is sample code for the same
I feel like all of these answers are slightly incomplete, so here's the proper way to add a viewController's view as a subview of another viewController's view:
If you'd like, you can copy this into your code as a snippet. SO doesn't seem to understand code replacement formatting, but they will show up clean in Xcode:
willMove is called automatically w/ addChild. Thanks @iOSSergey