【问题标题】:UIImage doesn't fade in/out when blur is on启用模糊时,UIImage 不会淡入/淡出
【发布时间】:2016-03-09 13:22:42
【问题描述】:

我有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)

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

【问题讨论】:

    标签: ios uiimageview uiviewanimation uiblureffect


    【解决方案1】:

    您将blurEffectView 添加为myImageView 的子视图,但您不能更改alpha 或为UIBlurEffectUIVisualEffectView 提供动画。取而代之的是,添加与 imageView 对象具有相同框架和约束的新 UIView,然后将效果添加为 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!)
    

    【讨论】:

    • 我将 blurEffectView 添加到 myImageView 是因为在我的 UIView 中,myImageView 前面有 UIView。现在,您的方法有效,但由于我向UIView 添加了模糊,因此该视图也被模糊了。任何想法,如何将一个视图带到模糊图像前面,淡入/淡出?
    猜你喜欢
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多