简体   繁体   English

将UIVisualEffectView添加到UITableView的背景视图仅适用于模拟器而非设备

[英]Adding UIVisualEffectView to UITableView's background view only works on simulator not device

I have a UITableView with a UIImageView as the backgroundView . 我有一个UITableViewUIImageView作为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;

look at this 看这个

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

相关问题 后台方法停止在设备上运行,仅适用于模拟器swift 4 xcode 9 - Background method stops running on device , only works on simulator swift 4 xcode 9 模糊视图可在模拟器中使用,但不能在设备上使用 - Blur View works in Simulator but not on device UIVisualEffectView活力未在设备上显示(但在模拟器中显示) - UIVisualEffectView vibrancy not showing on device(but showing in simulator) 后台任务仅在模拟器上有效 - Background Task works on Simulator only 发送到后台的本地通知可以在模拟器中运行,但不能在设备上运行 - Local notifications sent to background works in simulator but not on device iOS应用程序在模拟器中以后台模式工作,但在设备中不工作吗? - iOS app works in background mode in simulator but not in device? SwiftUI·后台定时器在模拟器上工作,但在真实设备上不工作 - SwiftUI · Background timer works on simulator but not on real device 将文件夹添加到iPad捆绑包适用于模拟器,而不适用于设备 - Adding folder to iPad bundle works on simulator, not on device UIVisualEffectView和UITableView - UIVisualEffectView and UITableView 将UITableView的实例添加到UIViewController的视图中,仅调整了其中一个 - Adding UITableView's instances to the view of UIViewController, only one of them was adjusted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM