以编程方式将ViewController呈现在其他控件之上 [英] Present ViewController on top of other programmatically

查看:46
本文介绍了以编程方式将ViewController呈现在其他控件之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码显示了我的视图控制器,而不是现有的视图控制器:

I have the following code which present my viewcontroller instead of an existing one:

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)

但是我想以编程方式在另一个视图的顶部显示视图控制器,

But I want to present the viewcontroller on top of the other one programmatically,

有什么想法吗?

推荐答案

如果希望看到模态视图控制器,尽管必须为其视图提供clear color背景.并将其modalPresentationStyle设置为.OverCurrentContext.

If you want your modal view controller to be see-though you have to give its view a clear color background. And set its modalPresentationStyle to .OverCurrentContext.

let vc = storyBoard.instantiateInitialViewController() as! MyPresenterViewController
vc.view.backgroundColor = .clearColor()
vc.modalPresentationStyle = .OverCurrentContext

viewControllerToPresentIn.presentViewController(vc, animated: true, completion: nil)

这篇关于以编程方式将ViewController呈现在其他控件之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆