Masked Uivisualeffectview Does Not Work on iOS 10

UIVisualEffectView in iOS 10

iOS 10 has changed the way UIVisualEffectView works, and it has broken many use cases which were not strictly speaking "legal", but worked before. Sticking to documentation, you should not be fading in UIVisualEffectView, which is what happens when you use UIModalTransitionStyleCrossDissolve. It seems now broken on iOS 10, along with masking of visual effect views, and others.

In your case, I would suggest an easy fix which will also create a better effect than before, and is supported on both iOS 9 and 10. Create a custom presentation and instead of fading the view in, animate the effect property from nil to the blur effect. You can fade in the rest of your view hierarchy if needed. This will neatly animate the blur radius similar to how it looks when you pull the home screen icons down.

UIVisualEffectView with mask layer

Ive now found a solution after digging around for a bit. Im assuming you're using Xcode 8 as the layer.mask has a known bug where you cannot have both a blur, and a mask on the same layer.

After messing around with a playground I have fixed the problem, so will try to adapt your code to match my solution. If you use the "mask" property of the blurView instead, then you should have no issues. There has been a bug report made to Apple I believe in regards to the layer.mask not working

This is your current code at the end

let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
maskLayer.fillRule = kCAFillRuleEvenOdd

let borderLayer = CAShapeLayer()
borderLayer.path = circle.cgPath
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 10
blur.layer.addSublayer(borderLayer)

blur.layer.mask = maskLayer

Instead of this, try using the following:

let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
maskLayer.fillRule = kCAFillRuleEvenOdd

let borderLayer = CAShapeLayer()
borderLayer.path = circle.cgPath
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.fillColor = UIColor.clear.cgColor //Remember this line, it caused me some issues
borderLayer.lineWidth = 10

let maskView = UIView(frame: self.view.frame)
maskView.backgroundColor = UIColor.black
maskView.layer.mask = maskLayer

blur.layer.addSublayer(borderLayer)
blur.mask = maskView

Let me know if you have any issues!

iOS 10 Blur Effects Prominent and Regular not working

What does that mean, and why aren't those two new blur effects working?

From WWDC 2016 Session 206: What's New in tvOS :

We've also added two new blur styles to the API.

You can now use UIBlurEffectStyleRegular or UIBlurEffectStyleProminent.

And we call these automatic styles.

And they'll actually adjust the effective blur effect style based on what the system setting is.

So if you use UIBlurEffectStyleRegular and the system's in light, it will use UIBlurEffectStyle.light.
If you use regular and dark, you'll use dark.

If you use prominent, it will use .extraLight and .extraDark.
.extraDark will be coming in a later seed

See all text of the session: http://asciiwwdc.com/2016/sessions/206

Basically this effects are for tvOS. That OS can be in dark or light style. For iOS those effects work in light mode.

swift UIVisualEffectView with mask autolayout varies by iOS device

Self-solved by the below code.
Received a hint from similar issue : 'https://stackoverflow.com/questions/58998541/swift-mask-uiview-constraints-issues/59037761'

override func viewDidAppear() {
self.setupBlur()
}


Related Topics



Leave a reply



Submit