0

我有UIImage这样模糊的:

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

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

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

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

4

1 回答 1

1

您将您添加blurEffectView为的子视图,myImageView但您不能更改 alpha 或为UIBlurEffectnor提供动画UIVisualEffectView。取而代之的是,添加与您的对象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!)
于 2016-03-09T14:34:13.857 回答