[Solved] Present a viewcontroller in UIView [closed]


To add a view controller to another view controller, you can do the following:

Inside the parent view controller class:

addChildViewController(someViewController)
view.addSubview(someViewController.view)
someViewController.didMove(toParentViewController: self)
someViewController.view.translatesAutoresizingMaskIntoConstraints = false

Then, set the layout constraints to position the view controller:

NSLayoutConstraint.activate([
    someViewController.view.leadingAnchor .constraint(equalTo: view.leadingAnchor ),
    someViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    someViewController.view.bottomAnchor  .constraint(equalTo: view.bottomAnchor  ),
    someViewController.view.topAnchor     .constraint(equalTo: view.topAnchor     )
])
view.layoutIfNeeded()

2

solved Present a viewcontroller in UIView [closed]