我的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}}
问题是,新图像只是出现而不是淡入。如果我禁用模糊,图像会淡入淡出。我做错了什么?
答案 0 :(得分:1)
您将blurEffectView
添加为myImageView
的子视图,但无法更改字母或向UIBlurEffect
或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!)