模糊视图控制器位于另一个模态呈现的视图控制器下方



我有一个应用程序,左上角有一个汉堡菜单。 按下时,菜单将以 90% 的不透明度淡入当前 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)
}

当菜单淡入时,如何模糊菜单后面的视图控制器?

您必须像这样将模糊效果应用于视图

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)

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

最新更新