简体   繁体   English

使用UIVisualEffectView创建模糊视图,在模拟器上更正,但在iphone和ipad上没有

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

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: 但是当我在iphone和ipads上运行它时,它看起来像: 在此输入图像描述

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 更多信息:我使用iphone6s,ipad air2,iOS 9.3.1 Xcode 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 我试图解决这个问题太累了,我尝试了其他方法,比如拍摄快照图像然后对图像应用模糊效果,但还有其他错误和其他CONs

UIVisualEffectView does not work with SpriteKit . UIVisualEffectView不适用于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. 我的猜测是底层实现使用了不起作用的不同API。 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. 模拟器会使用各种技巧来模拟实际设备,因此他们可能会使用不同于实际设备的东西,这就是它在模拟器上运行的原因。

在代码中删除此行

self.backgroundColor = UIColor.clearColor()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM