Reputation: 1736
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?
Upvotes: 0
Views: 108
Reputation: 1660
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!)
Upvotes: 1