[英]Present ViewController on top of other programmatically
我有以下代碼,它呈現我的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呈現在另一個上面 ,
有任何想法嗎?
如果您希望查看模態視圖控制器,則必須為其視圖提供clear color
背景。 並將其modalPresentationStyle
設置為.OverCurrentContext
。
let vc = storyBoard.instantiateInitialViewController() as! MyPresenterViewController
vc.view.backgroundColor = .clearColor()
vc.modalPresentationStyle = .OverCurrentContext
viewControllerToPresentIn.presentViewController(vc, animated: true, completion: nil)
我使用以下方法,以便僅在另一個視圖控制器的底部顯示我的視圖:
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)
如果您使用navigationcontroller,則可以將viewcontrollers更改為
navigationController?.presentViewController(newVC, animated: true, completion: nil)
但由於呈現不會從左或右帶來視圖,您將丟失導航控制器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.