【问题标题】:Remove BlurEffect before to use it with a button在与按钮一起使用之前删除 BlurEffect
【发布时间】:2017-08-05 10:41:39
【问题描述】:

我有一个按钮,当我点击它时,我的 background_image 会变成模糊效果。

 @IBAction func button_MainClicked2(_ sender: UIButton) {
        if button_MainCenter == button_viajes.center{
            UIView.animate(withDuration: 0.6, animations:

         {

            let blur = UIBlurEffect(style: UIBlurEffectStyle.light)
            let blurView = UIVisualEffectView(effect: blur)
            blurView.frame = self.image_Background.bounds
            self.image_Background.addSubview(blurView)    

        })
        } else {
            UIView.animate(withDuration: 0.6, animations: {
                // I want to remove blur effect as soon as i press the button again.
            })
        }
    }

如何修复它以在单击返回按钮时立即消除效果?

【问题讨论】:

    标签: swift button blur effect uiblureffect


    【解决方案1】:

    您可以在将 tag 添加为子视图之前添加 tag 以模糊视图,然后将其添加到动画块中

    for view in button_MainCenter.subviews {
        if view.tag == 1000 {
            view.removeFromSuperview()
        }
    }
    

    编辑: 不确定它是否会被动画化。如果不是,您可以将此视图的 alpha 动画从 1 到 0,然后将其删除。

    编辑:

     let blur = UIBlurEffect(style: UIBlurEffectStyle.light)
     let blurView = UIVisualEffectView(effect: blur)
     blurView.tag = 1000
     blurView.frame = self.image_Background.bounds
     self.image_Background.addSubview(blurView)
    

    【讨论】:

    • 如果你不想遍历子视图,你也可以直接说if let blurView = imageBackground.viewWithTag(tag: 1000) { ... }
    • 谢谢哥们,但还是不行。我需要在哪里添加这个标签?需要我先写这段代码吗?非常感谢
    猜你喜欢
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多