【问题标题】:use UIVisualEffectView to create a blur view, correct on simulator but not on iphone & ipad使用 UIVisualEffectView 创建模糊视图,在模拟器上正确但在 iphone 和 ipad 上不正确
【发布时间】:2016-04-06 06:08:31
【问题描述】:

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

我使用的代码:

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")
    }
}

结果: 在模拟器上一切正常:

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

请注意我没有更改“降低透明度”设置!

那么当我想在没有模糊的情况下拍摄这个黑色背景的快照时,你猜怎么着?!在照片流中,我看到了完全正确的模糊视图图片...

另外,当我双击home键,查看多任务界面时,我看到了模糊视图效果!

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

试图解决这个问题我很累,我尝试了其他方法,例如拍摄快照图像,然后对图像应用模糊效果,但有其他错误和其他缺点

【问题讨论】:

  • 你检查UIAccessibilityIsReduceTransparencyEnabled()返回的内容了吗?
  • @jelly 是的,请检查我的代码,有打印信息,我也检查了设置
  • 好吧,如果你不使用自动布局(如果你这样做,你必须确保你的 subivew 更新其超级视图的大小)或其他图形工具(如 SpriteKit 模糊效果不起作用)除了UIKit 它应该可以工作。
  • 我复制了您的代码,将 self.background 属性从 clearColor 更改为我自己的图案颜色。它在 iPhone 6 上运行良好。
  • 如果您使用精灵套件,这很可能是原因。不要指望它可以与 sprite kit 一起使用。

标签: ios swift uiview blur uivisualeffectview


【解决方案1】:

UIVisualEffectView 不适用于SpriteKit。我不知道他们在后面有什么不同,如果有人知道,请随时编辑答案。我的猜测是底层实现使用了不同的 API,它们不能一起工作。模拟器会使用各种技巧来模拟实际设备,因此他们可能会在背面使用与真实设备不同的东西,这就是它在模拟器上工作的原因。

【讨论】:

    【解决方案2】:

    删除代码中的这一行

    self.backgroundColor = UIColor.clearColor()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 2018-12-12
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多