Less Blur with `Visual Effect View with Blur`?

后端 未结 11 1311
死守一世寂寞
死守一世寂寞 2020-12-08 10:11

Title pretty much asks it all...

I\'m playing with the iOS8 Visual Effect View with Blur. It\'s over a UIImageView that shows a user choosa

11条回答
  •  春和景丽
    2020-12-08 10:55

    This works for me.

    I put UIVisualEffectView in an UIView before add to my view.

    I make this function to use easier. You can use this function to make blur any area in your view.

    func addBlurArea(area: CGRect, style: UIBlurEffectStyle) {
        let effect = UIBlurEffect(style: style)
        let blurView = UIVisualEffectView(effect: effect)
    
        let container = UIView(frame: area)
        blurView.frame = CGRect(x: 0, y: 0, width: area.width, height: area.height)
        container.addSubview(blurView)
        container.alpha = 0.8
        self.view.insertSubview(container, atIndex: 1)
    }
    

    For example, you can make blur all of your view by calling:

    addBlurArea(self.view.frame, style: UIBlurEffectStyle.Dark)
    

    You can change Dark to your desired blur style and 0.8 to your desired alpha value

提交回复
热议问题