我在第二个视图上分享了主屏幕:
从菜单中查看(左) 用containerview查看(右)。 我想在右侧容器视图中显示更多视图(如屏幕截图所示)。
这个选项是否可以使用containerview? 怎么做?有没有人有任何例子?
答案 0 :(得分:2)
是的,您可以在Container视图
中添加特定的ViewController作为子视图let controller = storyboard!.instantiateViewController(withIdentifier: "NameOfVCYouWantToAdd")
addChildViewController(controller)
controller.view.translatesAutoresizingMaskIntoConstraints = false
viewControllerContainer.addSubview(controller.view)
NSLayoutConstraint.activate([
controller.view.leadingAnchor.constraint(equalTo: viewControllerContainer.leadingAnchor),
controller.view.trailingAnchor.constraint(equalTo: viewControllerContainer.trailingAnchor),
controller.view.topAnchor.constraint(equalTo: viewControllerContainer.topAnchor),
controller.view.bottomAnchor.constraint(equalTo: viewControllerContainer.bottomAnchor)
])
controller.didMove(toParentViewController: self)
<强> viewControllerContainer 强> 是容器视图
答案 1 :(得分:0)
view.bringSubview(toFront: blablaViewController.view)
答案 2 :(得分:0)
将特定的ViewController呈现为MainviewController中的子视图
var selectionVc : YourViewController!
func display()
{
view.perform(#selector(self.view.endEditing(_:)), with: nil, afterDelay: 000.2)
if selectionVc == nil
{
selectionVc = storyboard?.instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
}
selectionVc.view.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4820205479)
selectionVc.superVc = self
// superVc your -- var superVc: mainViewController!
self.present(selectionVc, animated: false, completion: nil)
}