1

当我的 UIAlertController 通过 self.view addSubView 方法出现时,我在视图控制器中实现了 UIBlurEffect。但是,在我关闭警报控制器的操作代码中,需要几秒钟的延迟才能消除模糊效果。有什么滞后的原因吗?

// 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;
}
4

0 回答 0