UIVisualEffectView on UITableView background

I create a UITableViewController (at the root of the UINavigationController) and present it modally on top of another view controller. It works for me to such an extent that when loading a view and calling viewDidAppear, the visual effect looks good. But immediately after viewDidAppear, the visual effect disappears, and the tableview has a white background.

In my submitted UITableViewController, I added this to 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 cell.backgroundColor = [UIColor clearColor] in tableView cellForRowAtIndexPath: but that doesn't help either.

Again, I get the correct effect when loading the view, but it loses the blur background as soon as it appears on the screen. Any ideas what could go wrong? I also tried saving blueEffectView as a property in my view controller, but no luck

+6
source share
2 answers

The problem is that when you present the default view controller with the default settings, once it has finished capturing the screen, the main view controller seems to be essentially erased. That's why your blur effect looks great until the animation of the presentation is complete - the main view disappears.

In order to implement the desired behavior, you need to change the segue presentation style to what preserves the main view controller, such as Over Full Screen, and not the default. Screen.

Note that when you reject this modal presentation, viewDidAppear will not be called in the view controller's view, because it is now always displayed. This may bite you if you rely on this method to perform any function upon termination.

+3
source

Do you use storyboards?

Select the view controller that was used modally (or, if it was completed in another VC, select a wrapper) and set the "Presentation" field to "Full Screen" or "Context for Current Content". (I really don't know what the difference is, they both seem to be doing the same.)

Screenshot of Xcode

After that, your blur effect should just be Work β„’. Also, I think this is new in iOS 8, I haven't tested it in iOS 7 yet.

+6
source

Source: https://habr.com/ru/post/975768/


All Articles