在图像被解散后,UIImage背后的模糊不会消失

时间:2017-01-14 00:07:27

标签: ios swift uiimageview uiimage swift3

我点击它后,我一直试图在图像后添加模糊效果,但是,在我关闭图像后它不会消失。模糊不会消失。

func didTapImageView(_ sender: UITapGestureRecognizer) {

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = self.view.frame

    let imageView = sender.view as! UIImageView
    let newImageView = UIImageView(image: imageView.image)
    newImageView.frame = self.view.frame
    newImageView.layer.masksToBounds = true

    //newImageView.backgroundColor = UIColor.black.withAlphaComponent(1)
    newImageView.contentMode = UIViewContentMode.scaleAspectFit
    newImageView.isUserInteractionEnabled = true
    let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
    newImageView.addGestureRecognizer(tap)
    //blurEffectView.addGestureRecognizer(tap)
    self.view.addSubview(blurEffectView)
    self.view.addSubview(newImageView)
}

func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
    sender.view?.removeFromSuperview()
}

Image with blur in backgroud

如何在点击后删除模糊?而且,我如何全屏?它似乎也没有起作用。

1 个答案:

答案 0 :(得分:3)

在我看来,当您致电dismissFullScreenImage时,您只是从超级视图中移除了UIImageViewblurEffectView完全是一个单独的子视图。您必须为效果视图设置属性,然后在调用要删除的图像时将其删除。在课程顶部说出类似的内容:

var blurEffectView:UIVisualEffectView!

然后在didTapImageView

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame

然后,当您致电dismissFullScreenImage时,您需要说出以下内容:

func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
    sender.view?.removeFromSuperview()
    blurEffectView.removeFromSuperview()
}

我不知道你的意思是“如何让它全屏?” ..视觉效果已经全屏。至少它看起来就像你的截图。