[英]Adding UIVisualEffectView to UITableView's background view only works on simulator not device
I have a UITableView
with a UIImageView
as the backgroundView
. 我有一个
UITableView
, UIImageView
作为backgroundView
。 This works like a charm. 这就像一个魅力。 However, now I'm trying to blur this image (using
UIVisualEffectView
) so that the background of the tableView looks blurred. 但是,现在我正在尝试模糊此图像(使用
UIVisualEffectView
),以便tableView的背景看起来模糊。
However, my code somehow ignores the image and simply blurs the white background of the table view.
但是,我的代码以某种方式忽略了图像并简单地模糊了表格视图的白色背景。
Here is the code:
这是代码:
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebarImage"]];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[blurEffectView setFrame:tempImageView.bounds];
[tempImageView addSubview:blurEffectView];
self.tableView.backgroundView = tempImageView;
EDIT: After some more testing, I found that this works on the simulator, but not on the actual device. 编辑:经过一些测试后,我发现这可以在模拟器上运行,但不能在实际设备上运行。 I have attached screenshots below a well.
我在井下方附上了截图。 What's even more surprising is that when I comment out
[tempImageView addSubview:blurEffectView]
; 更令人惊讶的是,当我注释掉
[tempImageView addSubview:blurEffectView]
; the image shows up. 图像显示出来。 That means the image is being copied to the phone.
这意味着图像正被复制到手机中。
This has got to be one of the silliest problems I encountered. 这必须是我遇到的最愚蠢的问题之一。 Apparently, I had "Reduce Transparency" switched on in my iphone settings.
显然,我在iphone设置中打开了“Reduce Transparency”。 Hence the problem.
因此问题。 Hope this helps some other poor soul trying to conserve battery.
希望这有助于其他一些穷人试图节省电池。
You can detect when "Reduce Transparency" is enabled in iOS 8+ using: 您可以使用以下方法检测iOS 8+中何时启用“降低透明度”:
if (UIAccessibilityIsReduceTransparencyEnabled()) {
...
}
This blog post goes more in depth on detecting whether UIVisualEffectView
is available on a device. 这篇博文更深入地探讨了
UIVisualEffectView
是否在设备上可用。
try this 试试这个
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sidebarImage"]];
UIBlurEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView * blurEffectView;
blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = tempImageView.bounds;
[tempImageView addSubview:blurEffectView];
self.tableView.backgroundView = tempImageView;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.