使用UIVisualEffectView创建模糊视图,在模拟器上可正确显示,但在iPhone&平板电脑 [英] use UIVisualEffectView to create a blur view, correct on simulator but not on iphone & ipad

查看:156
本文介绍了使用UIVisualEffectView创建模糊视图,在模拟器上可正确显示,但在iPhone&平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:在应用中创建模糊视图.

The goal: create a blur view in app.

我使用的代码:

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:

但是当我在iPhone和iPad上运行它时,它看起来像:

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!

更多信息: 我使用iphone6s,ipad air2和iOS 9.3.1 Xcode 7.3版

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

推荐答案

UIVisualEffectView不适用于SpriteKit.我不知道他们后面的处理方式有什么不同,如果有人知道,请随时编辑答案.我的猜测是,底层实现使用了不同的API,这些API无法正常运行.该模拟器会执行各种技巧来模拟实际设备,因此它们在背面可能会使用与真实设备不同的东西,这就是为什么它可以在模拟器上运行的原因.

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.

这篇关于使用UIVisualEffectView创建模糊视图,在模拟器上可正确显示,但在iPhone&平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆