[英]Adding new Viewcontroller's view as subview
我正在尝试使用以下内容并且无法添加新的viewcontrollers视图。 这是呈现视图控制器的唯一方法吗? 我们不能从其他storyboard viewcontrollers视图添加视图吗?
//Working
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
self.present( viewcontroller , animated: true, completion: nil)
//Not working
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
vc.view.frame = self.view.frame
self.view.addSubview(vc.view)
您还需要在当前Controller中添加CustomViewController
作为ChildViewController
。
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
vc.view.frame = self.view.bounds
self.addChildViewController(vc)
self.view.addSubview(vc.view)
vc.didMove(toParentViewController: self) //OR vc.willMove(toParentViewController: self)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.