0

I want to blur my UITableView (inside a UITableViewController) when I present a UIAlertController (UIAlertControllerStyleActionSheet) but when using UIBlurEffect and UIVisualEffectView it doesn't blur the table view's content behind it; it just blocks it out. Happens on both simulator and device.

- (void)showAlert {
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = CGRectMake(0, self.tableView.contentOffset.y, self.view.frame.size.width, self.view.frame.size.height);

    [self.view addSubview:visualEffectView];

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert Title" message:@"Alert Message" preferredStyle:UIAlertControllerStyleActionSheet];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // handle choice...

        [visualEffectView removeFromSuperview];
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // handle choice...

        [visualEffectView removeFromSuperview];
    }]];

    [self presentViewController:alert animated:YES completion:nil];
}

Screenshot:

enter image description here

There is text content in the table view behind the action sheet that ought to be showing up as blurred, e.g. like in this image:

enter image description here

shim
  • 9,289
  • 12
  • 69
  • 108

1 Answers1

-1

I have tried on view and it works fine. I have made few changes in your code.

 - (void)showAlert {
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width, self.view.frame.size.height);

    //self.vBlur.backgroundColor = [UIColor clearColor];
    [self.view addSubview:visualEffectView];

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert Title" message:@"Alert Message" preferredStyle:UIAlertControllerStyleActionSheet];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // handle choice...

        [visualEffectView removeFromSuperview];
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"Action 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // handle choice...

        [visualEffectView removeFromSuperview];
    }]];

    [self presentViewController:alert animated:YES completion:nil];
}

screenshot

another screenshot?

shim
  • 9,289
  • 12
  • 69
  • 108
jiten
  • 137
  • 8
  • Your screenshot doesn't look fine to me. – shim Jun 29 '16 at 04:41
  • why? What's wrong into it? You want it full screen? – jiten Jun 29 '16 at 04:42
  • Does that look blurred to you? It's just a solid dark grey background behind the action sheet. – shim Jun 29 '16 at 04:43
  • If you change anything in uiblureffect enum like UIBlurEffectStyleExtraLight still you will not see a complete blur effect. – jiten Jun 29 '16 at 04:46
  • There is no blur effect working at all here, regardless of the enum choice. That's a solid background, just like mine. – shim Jun 29 '16 at 04:47
  • @shim got it. I have just changed one line in my code and it works fine. [self.vBlur addSubview:visualEffectView]; I have added visualeffectview instance in a view. – jiten Jun 29 '16 at 04:49
  • What is `self.vBlur`? – shim Jun 29 '16 at 05:01
  • In main view of uiviewcontroller i have added another view named as "vBlur" and then i have added visualeffectview to it. So that whatever controls i have added in main view will get blur. – jiten Jun 29 '16 at 05:17
  • Update your screenshot? – shim Jun 29 '16 at 05:19
  • i have added a new answer with two screenshots. have a look. – jiten Jun 29 '16 at 05:27
  • None of them look blurred to me. And you shouldn't add a separate answer with just links to images. – shim Jun 29 '16 at 13:33