You need to set constraints between current view controller and the embedded view controller. You also have to turn off translating autoresizing mask into constraints otherwise you will get double constraints and the view will not be positioned correctly.
This is a snippet that places a smaller view inside a view in current view controller:
if let vc = storyboard?.instantiateViewController(withIdentifier: "SmallViewController") as? SmallViewController {
// vc.view is the view of the embedded view controller
vc.view.translatesAutoresizingMaskIntoConstraints = false
// grayView is the small view in current view controller, that will contain the embedded view controller's view
grayView.addSubview(vc.view)
// define constraints between vc.view and grayView (top, bottom, left, right)
var constraints = [NSLayoutConstraint]()
constraints.append(NSLayoutConstraint(item: vc.view, attribute: .leading, relatedBy: .equal, toItem: grayView, attribute: .leading, multiplier: 1, constant: 0))
constraints.append(NSLayoutConstraint(item: vc.view, attribute: .trailing, relatedBy: .equal, toItem: grayView, attribute: .trailing, multiplier: 1, constant: 0))
constraints.append(NSLayoutConstraint(item: vc.view, attribute: .top, relatedBy: .equal, toItem: grayView, attribute: .top, multiplier: 1, constant: 0))
constraints.append(NSLayoutConstraint(item: vc.view, attribute: .bottom, relatedBy: .equal, toItem: grayView, attribute: .bottom, multiplier: 1, constant: 0))
grayView.addConstraints(constraints)
}
I highly recommend using PureLayout for making constraints in code as it is much easier and more readable