【问题标题】:Programmatically blur background view behind Pop Over以编程方式模糊 Pop Over 背后的背景视图
【发布时间】:2017-06-08 02:21:17
【问题描述】:

我有一个视图控制器 (PopOverViewController) 被另一个视图控制器 (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 关闭时让模糊消失。

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

谢谢!

斯威夫特 3

【问题讨论】:

标签: ios swift modalviewcontroller uivisualeffectview


【解决方案1】:
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()
        }
    }

【讨论】:

    猜你喜欢
    • 2016-04-22
    • 2015-10-26
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多