Less Blur with `Visual Effect View with Blur`?

后端 未结 11 1314
死守一世寂寞
死守一世寂寞 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 11:02

    A solution similar to some here, but simpler, is to use a UIViewPropertyAnimator (iOS 10+) and set its fractionComplete property to some value between 0 and 1.

        // add blur view to image view
        let imgBlur = UIVisualEffectView()
        imgView.addSubview(imgBlur)
        imgBlur.frame = imgView.bounds
    
        // create animator to control blur strength
        let imgBlurAnimator = UIViewPropertyAnimator()
        imgBlurAnimator.addAnimations {
            imgBlur.effect = UIBlurEffect(style: .dark)
        }
    
        // 50% blur
        imgBlurAnimator.fractionComplete = 0.5
    

    Note, if you plan to vary fractionComplete based on a pan gesture, scroll view, slider, etc. you'll want to set pausesOnCompletion = true (iOS 11+).

提交回复
热议问题