在另一个模态呈现的viewController下面模糊viewController?

时间:2016-06-08 03:50:40

标签: ios xcode swift uivisualeffectview

我的应用程序左上角有一个汉堡菜单。按下时,菜单以90%的不透明度淡入当前ViewController,显示应用程序的主要导航选项。

我使用以下代码从页面呈现viewController:

@IBAction func navToMenu(sender: AnyObject) {

    let vc = self.storyboard!.instantiateViewControllerWithIdentifier("mainMenu")
    vc.view.backgroundColor = UIColor(red: 240/255, green: 112/255, blue: 49/255, alpha: 0.9)
    vc.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen
    vc.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve

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

}

当它淡入时,如何模糊菜单后面的viewController?

1 个答案:

答案 0 :(得分:0)

您必须将模糊效果应用于此视图

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.addSubview(blurEffectView)

现在编写添加视图的代码。