簡體   English   中英

將UIVisualEffectView添加到UITableView的背景視圖僅適用於模擬器而非設備

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

我有一個UITableViewUIImageView作為backgroundView 這就像一個魅力。 但是,現在我正在嘗試模糊此圖像(使用UIVisualEffectView ),以便tableView的背景看起來模糊。 但是,我的代碼以某種方式忽略了圖像並簡單地模糊了表格視圖的白色背景。 這是代碼:

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;

編輯:經過一些測試后,我發現這可以在模擬器上運行,但不能在實際設備上運行。 我在井下方附上了截圖。 更令人驚訝的是,當我注釋掉[tempImageView addSubview:blurEffectView] ; 圖像顯示出來。 這意味着圖像正被復制到手機中。

物理電話

模擬器

這必須是我遇到的最愚蠢的問題之一。 顯然,我在iphone設置中打開了“Reduce Transparency”。 因此問題。 希望這有助於其他一些窮人試圖節省電池。

您可以使用以下方法檢測iOS 8+中何時啟用“降低透明度”:

if (UIAccessibilityIsReduceTransparencyEnabled()) {
   ...
}

這篇博文更深入地探討了UIVisualEffectView是否在設備上可用。

試試這個

 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM