6
votes

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

2
do you have a solution for the problem? I think I have the same problem. After setting the BackgroundView tableView.backgroundView i have a light grey BackgroundView without any blur effect.Stone
@Stone hi, I got the same issue. Do you had any idea?Zigii Wong
@Wongzigii unfortunately no. still no solution.Stone
@Stone I finally found the answer. vc.modalPresentationStyle = UIModalPresentationOverFullScreen; try this code.Zigii Wong
@Wongzigii wow awesome, thanks.Stone

2 Answers

3
votes

The problem is, when you present a view controller modally with the default settings, once it has finished taking over the screen, the underlying view controller seems to be essentially erased. This is why your blur effect looks great until the presentation animation completes - the underlying view vanishes.

To implement the desired behavior, you'll need to change the segue presentation style to something that will preserve the underlying view controller, like Over Full Screen instead of the default Full Screen.

Note that when you dismiss this modal presentation, viewDidAppear will not be called on the presenting view controller, because it's now always visible. That can bite you if you were relying on that method to perform any function upon dismissal.

6
votes

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.