ios - 以编程方式模糊 Pop Over 后面的背景 View

标签 ios swift modalviewcontroller uivisualeffectview

我有一个 View Controller (PopOverViewController)被另一个 View Controller (ListViewController)实例化。

ListViewController内,PopOverViewController 以模态方式呈现:

popOverVC = self.storyboard?.instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController

popOverVC.modalPresentationStyle = .fullScreen

PopOverViewController内,PopOverViewController 通过 CGAfflineTransformation 进行动画输入/输出:

    func showAnimate()
{
    self.shadowView.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
    self.view.alpha = 0.0;
    UIView.animate(withDuration: 0.3, animations: {
        self.view.alpha = 1.0
        self.shadowView.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
    });
}

func removeAnimate()
{
    UIView.animate(withDuration: 0.3, animations: {
        self.shadowView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
        self.view.alpha = 0.0;
    }, completion:{(finished: Bool) in
        if (finished)
        {
            self.view.removeFromSuperview()
        }
    });
}

在PopOverViewController的viewDidLoad中,背景颜色调低:

self.view.backgroundColor = UIColor(white: 0, alpha: 0.7)

我的问题: 当 PopOver 呈现时,由于 PopOver 的 Alpha,背景仍然可见。我想在呈现 PopOver 时模糊此背景,并在关闭 PopOver 时使模糊消失。

我对如何做到这一点感到困惑。

谢谢!

swift 3

最佳答案

private func makeEffectView() {
        let effect: UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
        effectView = UIVisualEffectView(effect: effect)
        effectView.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height)
        self.window?.addSubview(effectView)
    }



private func removeEffectView() {
        if effectView != nil {
            self.effectView.removeFromSuperview()
        }
    }

关于ios - 以编程方式模糊 Pop Over 后面的背景 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44425625/

相关文章:

ios - View 和标签栏之间的 UITabBar 线

ios - Swift 3.0 - 根据 2 个不同枚举的每种情况调用函数

ios - 在 iOS 上使用 swift 将出生日期转换为带有本地化年份标签的年龄

iPhone模态视图-如何返回父父 Controller

ios - 模态视图 Controller 在呈现 2/3 次后不再呈现

iphone - 作为模态视图 Controller 调用底层 ViewController 中的函数被取消

ios - 如何在不创建 *Cell.swift 文件的情况下访问 UITableViewCell 对象

objective-c - 如何从 Core Data 实体对象的 NSArray 中提取选定的属性并形成联合字符串?

ios - UINavigationController 仅在第二次出现 View 时隐藏后退按钮

ios - 获取持久协调器时核心数据奇怪崩溃