我有以下代码显示现有的viewcontroller 而不是:
let frameworkBundle = NSBundle(identifier: "me.app.MyFramework")
var storyBoard:UIStoryboard = UIStoryboard(name: "MyStoryboard", bundle: frameworkBundle)
var vc = storyBoard.instantiateInitialViewController() as MyPresenterViewController
viewControllerToPresentIn.presentViewController(vc, animated: true, completion: nil)
但我想以编程方式呈现另一个的viewcontroller
任何想法?
答案 0 :(得分:34)
如果您希望查看模态视图控制器,则必须为其视图提供clear color
背景。并将其modalPresentationStyle
设置为.OverCurrentContext
。
let vc = storyBoard.instantiateInitialViewController() as! MyPresenterViewController
vc.view.backgroundColor = .clearColor()
vc.modalPresentationStyle = .OverCurrentContext
viewControllerToPresentIn.presentViewController(vc, animated: true, completion: nil)
答案 1 :(得分:6)
我使用以下方法只在另一个视图控制器的底部显示我的视图:
var presenterStoryBoard:UIStoryboard = UIStoryboard(name: "MiniAppPanel", bundle: frameworkBundle)
var vc = presenterStoryBoard.instantiateInitialViewController() as MiniAppPanelViewController
vc.view.frame = CGRectMake(0, vc.view.frame.size.height - 120, vc.view.frame.size.width, 120)
publisherViewController.addChildViewController(vc)
publisherViewController.view.addSubview(vc.view)
答案 2 :(得分:0)
如果使用导航控制器,则可以将viewcontrollers更改为
navigationController?.presentViewController(newVC, animated: true, completion: nil)
但由于展示不会从左侧或右侧带来视图,您将失去导航控制器