efremidze/VisualEffectView

cannot support iOS 14

azureplus opened this issue Β· 39 comments

cannot support iOS 14

can you elaborate?

In ios 13 and earlier it looks like this
image
But in iOS 14 its like this :
image

yes,i have the same problem。

Thanks for demonstrating, needs investigation.

Thanks

Same in my app - blurring is broken in iOS 14

same problem

same here πŸ˜‚

Yep, same problem here - any update?

The UIImage+ImageEffects extension provided by Apple (which creates a UIImage replicating UIBlurEffect) is also broken under iOS14. Same result: monochrome and no blur.

Luckily SwiftUI lets you specify a blur radius - no private api required. So I plan to stop using this framework, and instead just wrap a SwiftUI view with a blur effect for iOS 13/14 users.

@zporges Can you share a snippet code or documentation page for how to specify blur radius on SwiftUI?

@zporges Next to blur I also need to darken and saturatize the view. If the saturation(amount:) modifier in SwiftUI handles values bigger than 1 this may work. I also need to animate the blurradius. Not so familiar with SwiftUI so I'll need to do some experimenting.

@zporges Can you share a snippet code or documentation page for how to specify blur radius on SwiftUI?

It's as simple as:

ViewToBlur()
    .blur(radius: 20)

https://developer.apple.com/documentation/swiftui/view/blur(radius:opaque:)

SwiftUI is an alternative; however only 81% of iOS devices that are currently active are running iOS 13, so there's still nearly 20% of the market for which SwiftUI isn't a viable option assuming you're trying to reach as much of the iOS market as possible.

You could conditionally do a SwiftUI Blur on iOS 13+ and a VisualEffectView on iOS 12 and earlier though

Yeah fair; though I'm struggling to get SwiftUI blurring contents behind the SwiftUI view in the same manner that the VisualEffectView does?

Hopefully Apple fixes the UIVisualEffectView bugs

I'm a little confused as to why this is being considered an Apple bug? The default UIVisualEffectView is still working as expected when used, it is just this framework not working. Thankfully for my needs I can temporarily use the default, it just won't look as.... nice.

If you know how to get it working, please make a PR!

lol I'm not smart enough to know why UIVisualEffectView is working and this framework isn't (even though VisualEffectView is a subclass of UIVisualEffectView) in my project at least. That's why I was asking about why this is being considered an apple bug, I was curious so as to learn. I read the thread above but i didn't really follow it

Currently researching a proper solution. Will keep everyone posted.

@mmdock VisualEffectView uses a private/hidden class named _UICustomBlurEffect instead of the default UIBlurEffect, because _UICustomBlurEffect has properties to manage blur radius. _UICustomBlurEffect is written by Apple but it is not part of public API. The implementation of _UICustomBlurEffect is changed on iOS 14 and it no longer works. It is not Apple's bug, but it is caused by Apple. We were taking this risk by using private API.

Same problem.

But I found a good idea here: https://stackoverflow.com/a/55378168/3449400
Just use UIVisualEffectView.alpha for animation and UIVisualEffectView.fractionComplete to set blur intensity.

Yes, it isn't like a "real blur" animation, but it is still smooth, non resource-intensive and blurs in a real time.

Thanks @unboxme
According to your clue, I write this class to replace this function


import UIKit

class GPCVisualEffectView: UIVisualEffectView{
    private lazy var blurAnimator = UIViewPropertyAnimator(duration: 0.5, curve: .linear, animations: nil)
    
    init() {
        super.init(effect: nil)
        configAnimator()
    }
    
    init( frame: CGRect) {
        super.init(effect: nil)
        self.frame = frame
        configAnimator()
    }
    
    override init(effect: UIVisualEffect?) {
        super.init(effect: nil)
        configAnimator()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        configAnimator()
    }
    
    private func configAnimator() {
        effect = nil
        autoresizingMask = [.flexibleHeight, .flexibleWidth]
        blurAnimator.addAnimations {
            self.effect = UIBlurEffect(style: .light)
        }
        blurAnimator.fractionComplete = 0.07
    }

}


usage

let overlay = GPCVisualEffectView()
overlay.frame = xxx
view.addSubview(overlay)

Note that: this workaround is just suitable for settled blur-alpha because of UIViewPropertyAnimator Issue

Is there a Hero to save us?

@zolobdz thank you for your code. But I have a question. What about custom colorTint? Because it's only one reason what I use this library.

cuzv commented

@unboxme @zolobdz UIViewPropertyAnimator workaround has another problem remain unresolved: fichek/AnimateBlurRadius#1

@Maxim-Zakopaylov Hi, you can set UIVisualEffect.backgroundColor in addAnimations closure, but don't forget to set color alpha. I hope this will help.

blurAnimator.addAnimations {
     self.effect = UIBlurEffect(style: .light)
     self.backgroundColor = UIColor.blue.withAlphaComponent(0.2)
}

@cuzv Thank you for reminding. Yes, this issue still exists. the workaround i provide is just suitable for settled blur-alpha. I will update my comment.

Hello! I've made a solution. https://github.com/perfectdim/CustomBlurEffectView
IOS 13- version is based on this repo, and for IOS 14+ there is a temporary working solution.

@perfectdim New repo? not PR?

@perfectdim Your repo? not PR? kkk

@HanSJin I'm sorry, what you mean? =)

@perfectdim Thanks for your solution :)
but I am not sure whether to use this VisualEffectView or your NEW CustomBlurEffectView repository.
Because I don't know if your repository will be updated in the future.
Anyway, your solution works well πŸ‘πŸ»

@HanSJin I will use my solution on my project, so I hope I will update it if needed =)
If guys from VisualEffectView will check my solution and integrate it to their module it will be ok for me =)
I didn't use PR, because my solution partly rebuilt what was made in VisualEffectView, and I'm not sure, that it is ok for them =)

Hey guys! After a couple days of research I found another solution without modifying UIBlurEffect directly and without subclassing UIVisualEffectView. So I added a my vision of blurring implementation [here].

Current version works only on iOS 13+, but next week I planned to add iOS 10+ support (I suppose it will based on UIBlurEffect).

Feel free to use my approach anywhere.

@unboxme Your solution appears to work. I can update VisualEffectView to use the same approach for iOS 13+.

I’ll push an update today.

Thank you!!!

Hey guys, was wondering if any of you could potentially help me please as ive been stuck on this issue for a while.

I cant seem the blur effect to work on iOS14 devices, it works fine on iOS13 though.

    let blurEffect = (NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type).init()
    blurEffect.setValue(8, forKeyPath: "blurRadius")
    blurView = UIVisualEffectView(effect: blurEffect)
    blurView.frame = UIScreen.main.bounds
    blurView.alpha = 1
    view.insertSubview(blurView, aboveSubview: imvBackground)

Is anyone please able to help me fix this? Thanks.