add UIViewController in subview

后端 未结 9 2231
情深已故
情深已故 2020-12-14 20:21

I don\'t know if this is the right key to search \"add UIViewController in subview\". As what you can see in my image ,there are two ViewController, the main and the second

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 20:55

    let controller:SecondViewController = self.storyboard!.instantiateViewController(withIdentifier: "secondViewController") as! SecondViewController

    controller.view.frame = self.view.bounds

    controller.willMove(toParent: self)

    self.view.addSubview(controller.view)

    self.addChild(controller)

    controller.didMove(toParent: self)

提交回复
热议问题