无法让我的ViewController显示在我当前的ViewController之上

时间:2014-11-19 04:43:59

标签: ios objective-c iphone swift uiviewcontroller

好吧,所以我此时尝试了多种方法。

方法1:使用其视图呈现新的viewcontroller。顺便说一下,这两种方法都涉及首先添加一个VisualEffectView,我不知道它是否会影响放在它上面的视图。

var vsView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Dark))
vsView.frame = parentView!.frame
self.parentView!.addSubview(vsView)
var vc = self.parentController!.storyboard?.instantiateViewControllerWithIdentifier("GoalTableView") as GoalsViewController
vc.view.backgroundColor! = UIColor.clearColor()
var vcView = vc.view
vcView.frame = CGRectMake(0, 0, self.parentView!.frame.width, self.parentView!.frame.height)
self.parentView!.addSubview(vc.view)

我对这种方法的问题是,新视图在新视图上看起来完美了大约半秒钟然后它的消失就消失了。它(可能)仍然活跃,因为它仍然捕获我的水龙头但最终它崩溃了。

方法2:在不提取视图的情况下,在新的ViewAtroller上呈现新的ViewController模式AKA。

var vsView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Dark))
vsView.frame = parentView!.frame
self.parentView!.addSubview(vsView)
var vc = self.parentController!.storyboard?.instantiateViewControllerWithIdentifier("GoalTableView") as GoalsViewController
vc.view.backgroundColor! = UIColor.clearColor()
self.parentController!.presentViewController(vc, animated: true, completion: nil)
vc.presentingViewController!.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.parentController!.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
vc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

这次它确实出现在新的viewcontroller上,但现在有了黑色背景(我认为这是出于资源管理的原因 - 它摆脱了旧的vc)。我不确定我是否正确使用UIModalPresentationStyle,但无论我应用什么vc或什么vc,它似乎没有什么区别。

有人可以提出一些想法吗?在这一点上我不知道该怎么做因为我认为使用vc视图的原始方法肯定会有效,但显然不是......我甚至没有尝试添加vsView,只是将vc.view添加到parentView但是这也不起作用!

0 个答案:

没有答案