0

I have UIImage which is blurred like this:

myImageView.image = UIImage(named: imageSet[0])
        let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
        blurEffectView = UIVisualEffectView(effect: blurEffect)
        blurEffectView?.frame = view.bounds
        myImageView.addSubview(blurEffectView!)

and then I want to fade in new UIImage like this:

UIView.transitionWithView(self.backgroundImageView,
        duration:1.0,
        options: UIViewAnimationOptions.TransitionCrossDissolve,
        animations: { self.myImageView.image = UIImage(named: self.imageSet[randomInt]
        },
        completion: nil)

and the problem is, new image simply appears, rather than fade in. If I disable blur, images fade in and out. What I am doing wrong?

Xernox
  • 1,706
  • 1
  • 23
  • 37

1 Answers1

1

You add your blurEffectView as a subview of myImageView but you can not change alpha or give animation to UIBlurEffect nor UIVisualEffectView. Instead of that, add new UIView with same frame and constraints as your imageView object then add your effects as a subview of a UIView object ;

myImageView.image = UIImage(named: imageSet[0])
let animationView = UIView(frame: myImageView.bounds)
animationView.backgroundColor = .clearColor()
blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style:.Light))
blurEffectView?.frame = animationView.bounds
view.addSubview(animationView)
animationView.addSubview(blurEffectView!)
Kemal Can Kaynak
  • 1,638
  • 14
  • 26
  • I was adding `blurEffectView` to `myImageView` because in my UIView I have `UIView` in front of `myImageView`. Now, you method works, but since I am adding blurr to `UIView`, that view is being blurred as well. Any ideas, how to bring that one view in front of blurred image, that fades in/out? – Xernox Mar 09 '16 at 16:57