use UIVisualEffectView to create a blur view, correct on simulator but not on iphone & ipad

十年热恋 提交于 2019-12-13 13:31:08

问题


The goal: create a blur view in app.

The code I use:

func createBlurBackgroundView() 
{
    if !UIAccessibilityIsReduceTransparencyEnabled() 
    {
        if blurredSubView == nil || blurredSubView.superview == nil 
        {
            print("Create blurred background view")
            self.backgroundColor = UIColor.clearColor()
            let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
            blurredSubView = UIVisualEffectView(effect: blurEffect)
            blurredSubView.frame = self.bounds
            self.insertSubview(blurredSubView, atIndex: 0)
        }
    }
    else 
    {
        print("Transparency disabled!! no blur view")
    }
}

The result: everything works fine on the simulator:

But when I ran it on the iphone and ipads, it looks like:

PLEASE NOTE I DIDN'T CHANGE THE "REDUCE TRANSPARENCY" SETTINGS!

Then when I want to take a snapshot of this black background without blur, guess what?! in the photo stream, I saw exactly the correct blur view picture...

Also, when I double clicked home button, and look at the multi-task interface, I saw the blur view effect!

More Info: I use iphone6s, ipad air2, both iOS 9.3.1 Xcode version 7.3

I'm so tired on trying to solve this problem, I tried other methods like take snapshot image and then apply blur effect on the image, but has other bugs and other CONs


回答1:


UIVisualEffectView does not work with SpriteKit. I don't know what they do differently in the back, if someone knows please feel free to edit the answer. My guess is that the underlying implementation use different APIs that don't work togheter. The simulator does all kinds of tricks to simulate the actual device so they might use something different in the back than the real devices and that's why it does work on a simulator.




回答2:


Remove this line in your code

self.backgroundColor = UIColor.clearColor()


来源:https://stackoverflow.com/questions/36442859/use-uivisualeffectview-to-create-a-blur-view-correct-on-simulator-but-not-on-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!