我有一个视图控制器(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关闭时模糊消失。
我很难过如何做到这一点。
谢谢!
Swift 3
答案 0 :(得分:0)
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()
}
}