Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIVisualEffectView on UITableView background

I am creating a UITableViewController (at the root of a UINavigationController) and presenting this modally on top of another view controller. I have it working to an extent, such that when the view loads and viewDidAppear is called, the visual effect looks good. But right after viewDidAppear, the visual effect goes away and the tableview has a white background.

In my presented UITableViewController, I added this in viewDidLoad:

if (NSClassFromString(@"UIVisualEffectView") && !UIAccessibilityIsReduceTransparencyEnabled()) {
    self.tableView.backgroundColor = [UIColor clearColor];
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    [blurEffectView setFrame:self.tableView.frame];

    self.blurView = blurEffectView;
    self.tableView.backgroundView = self.blurView;
}

I also implement this, to make sure the cells have a clear background:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (NSClassFromString(@"UIVisualEffectView") ) {
        cell.backgroundColor = [UIColor clearColor];
    }
}

I also set the cell.backgroundColor = [UIColor clearColor] in tableView's cellForRowAtIndexPath: but that doesn't help either.

Again, I get the correct effect when the view loads, but it loses the blur background as soon as it appears on screen. Any ideas what might be going wrong? I have also tried to retain the blueEffectView as a property in my view controller, but no luck

like image 493
Z S Avatar asked Sep 24 '14 11:09

Z S


1 Answers

Are you using Storyboards?

Select the view controller that's used modally (or if it's wrapped in another VC, select the wrapper) and set the Presentation combo box to "Over Full Screen" or "Over Current Context". (I don't actually know what the difference is, they both seem to do the same thing.)

Screenshot of Xcode

After doing that, your blur effect should Just Work™. Also, I think this is new in iOS 8, I haven't tested this in iOS 7 yet.

like image 69
Peter W. Avatar answered Sep 28 '22 06:09

Peter W.