我有一个视图控制器(PopOverViewController)被另一个视图控制器(ListViewController)实例化。
在ListViewController中,以模式方式显示PopOverViewController:
popOverVC = self.storyboard?.instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpViewController
popOverVC.modalPresentationStyle = .fullScreen
在PopOverViewController中,使用CGAfflineTransformation对PopOverViewController进行动画输入/输出:
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
最佳答案
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 - 以编程方式模糊弹出后的背景 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44425625/