I have setup a simple layout with a button which, when pressed, causes the storyboard subview to load a xib file and assigns its view to the storyboard subview. The problem is that the xib view causes the storyboard subview to 'break' its original constraints:
Here's the main storyboard (left) and xib view (right):
Here's what happens when I press the button on the main storyboard.
- (IBAction)btnShowView:(id)sender {
xibViewController *xib_VC = [[xibViewController alloc] initWithNibName:nil bundle:nil];
xib_VC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
//xib_VC.view.frame.size = self.myView.frame.size;
UIView *view = xib_VC.view;
[self.myView addSubview:view];
}
And here's the result - you can see that the xib view has caused the main storyboard subview to go outside of its constraints.
I'm guessing that dynamically changing the storyboard subview overwrites its original view and constraints? Do I have to programatically add these constraints again before assigning the xib view to the storyboard subview?



By your descriptions, it looks like your intention is to put newly created view(xib_VC.view) in the position of myView.
By code you mentioned is adding xib_VC.view to myview as a subview,It doesn't any constraints to it or provides a frame to
view.Setting
xib_VC.view.frame.sizewill not going to work, this is frame for view in xib_VC.If you just need view, then you don't have to create view controller xib. Just create view xib.
Following line no use, since you are not using a controller.
xib_VC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;