uiimageviewuivisualeffectviewuiblureffectanimatewithduration

swift cancel blur effect slowly


I'm trying to unblur my image slowly, i blurred it with this code

 let blur = UIBlurEffect(style: UIBlurEffectStyle.light)
        let blurView = UIVisualEffectView(effect: blur)
        blurView.frame = imageview.bounds
        imageview.addSubview(blurView)

then i tried to unblur my image with this code :

UIView.animate(withDuration: 6.0) {
            blurView.alpha = 0.5
}

The problem is that there is no effect going on, the image is loading with 0.5 alpha.


Solution

  • The problem was that my unblur effect was in the viewDidLoad Method, i had to put it in the viewDidApper Method.