[英]use UIVisualEffectView to create a blur view, correct on simulator but not on iphone & ipad
目标:在应用中创建模糊视图。
我使用的代码:
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")
}
}
结果:在模拟器上一切正常:
请注意我没有改变“减少透明度”设置!
然后,当我想拍摄这个黑色背景的快照而不模糊时,猜猜是什么?! 在照片流中,我看到了正确的模糊视图图片......
另外,当我双击主页按钮,并查看多任务界面时,我看到了模糊视图效果!
更多信息:我使用iphone6s,ipad air2,iOS 9.3.1 Xcode 7.3版
我试图解决这个问题太累了,我尝试了其他方法,比如拍摄快照图像然后对图像应用模糊效果,但还有其他错误和其他CONs
UIVisualEffectView
不适用于SpriteKit
。 我不知道他们在后面做了什么不同,如果有人知道,请随时编辑答案。 我的猜测是底层实现使用了不起作用的不同API。 模拟器会使用各种技巧来模拟实际设备,因此他们可能会使用不同于实际设备的东西,这就是它在模拟器上运行的原因。
在代码中删除此行
self.backgroundColor = UIColor.clearColor()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.