1

I implemented UIBlurEffect in my view controller when my UIAlertController appears via self.view addSubView method. However, in the action code where I had dismissed the alert controller, it takes a couple of seconds of lag before the blur effect is removed. Is there any reason for the lag?

// Create effect
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
// Add effect to an effect view
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.view.frame;

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Input Required" message:@"You are using UIAlertController" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = nil;

if(self.m_txtStaffID.text.length == 0)
{
    // Add the effect!
    [self.view addSubview:visualEffectView];

    cancel = [UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action)
              {
                  [self.m_txtStaffID becomeFirstResponder];
                  [visualEffectView removeFromSuperview]; // this takes a full 1-2 seconds to take effect
                  [alert dismissViewControllerAnimated:YES completion:nil]; // but this is almost immediately!
              }];
    [alert addAction:cancel];

    alert.message = @"Enter your staff ID and try again";
    [self presentViewController:alert animated:YES completion:nil];
    return;
}
CyberMew
  • 1,159
  • 1
  • 16
  • 33

0 Answers0