How to remove the Blur Effect

Asked 2 years ago, Updated 2 years ago, 122 views

I have a question about how to remove the Swift Blur.


at the same time PopUp View was removed with the following code: I would like to remove the Blur Effect from Button.

import UIKit

classViewController:UIViewController {

/* PopUp View*/
@IBOutlet variableItemView:UIView!

/* Background Image*/
@IBOutlet weak varbackgroundImg: UIImageView!

/* Blur Effect*/
@ IBAction func BlurEffect(_sender:Any){


    /* setting of addItemView*/
    addItemView.center=self.view.center


    /* Setting of Animation*/
    self.backgroundImg.addBlurEffect()/*Blur*/
    addItemView.transform=CGAffineTransform.init(scaleX:1.3, y:1.3)
    addItemView.alpha = 0

    UIView.animate(withDuration:0.4){
        self.view.addSubview(self.addItemView)
        self.addItemView.alpha=1
        self.addItemView.transform=CGAffineTransform.identity
    }


}

/* I want to remove blur effect*/
@ IBAction func removeBlurEffect(_sender:Any){

UIView.animate(withDuration: 0.3, animations: {
    self.addItemView.transform=CGAffineTransform.init (scaleX: 1.3, y: 1.3)
    self.addItemView.alpha = 0

}) {(success:Bool) in

    self.addItemView.removeFromSuperview()

    }

}




override func viewDidLoad(){
    super.viewDidLoad()

    addItemView.layer.cornerRadius=5

}

override funcdidReceiveMemoryWarning(){
     super.didReceiveMemoryWarning()



}


}

extension UIImageView
{

funcaddBlurEffect(){

let blurEffect = UIBlurEffect (style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView (effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview (blurEffectView)

    }

}

How do I remove the Blur multiplied by the extension function?

The URL of GitHub is as follows.
https://github.com/TakanoriHasebe/udemy-questions/tree/master/SwiftBlurEffect

Thank you for your understanding.

swift ios swift3

2022-09-30 21:23

1 Answers

Now that you have added a method of blurring the UIImageView using Extension, it is natural to define a method of removing blur in Extension.

extension UIImageView {

    funcaddBlurEffect(){
        .... (omitted)....
    }

    func removeBlurEffect(){
        // For all UIImageView subviews, click
        self.subviews.forEach {
        // A subview that can cast a type into a UIVisualEffectView, i.e., a type of UIVisualEffectView, is a subview that can be used as a
        iflet effectView=$0 as ?UIVisualEffectView{
            // Remove from superview.
            effectView.removeFromSuperview()
        }
    }

}

You can remove the Blur by running backgroundImg.addBlurEffect() to apply Blur.backgroundImg.removeBlurEffect().

How do I remove the Blur?

Knowing that is what you did to apply Blur.Why don't we do the opposite?This is also a natural way of thinking.
Since self.addSubview(blurEffectView) and UIImageView were blurred by addSubview(), the hypothesis is that removeFromSuperview() might remove the blur.All you have to do is verify it.

 CGAffineTransform.init (scaleX: 1.3, y: 1.3)

Initiator formats are special and should be distinguished from general method (function) formats.

 init(scaleX:y:)

If you put it in the reference like this,

 CGAffineTransform (scaleX: 1.3, y: 1.3)

and


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.