当模糊打开时,UIImage不会淡入/淡出

时间:2016-03-09 13:22:43

标签: ios uiimageview uiviewanimation uiblureffect

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

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

然后我想要像这样淡出新的UIImage:

{{1}}

问题是,新图像只是出现而不是淡入。如果我禁用模糊,图像会淡入淡出。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您将blurEffectView添加为myImageView的子视图,但无法更改字母或向UIBlurEffectUIVisualEffectView提供动画。取而代之的是,添加与UIView对象具有相同框架和约束的新imageView,然后将效果添加为UIView对象的子视图;

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!)