UIAlertController解雇很慢

在iOS 8之后,将我的实现更改为UIAlertController而不是UIAlertView让我感到头痛。

在点击按钮后UI变为响应之前,解雇需要大约一秒钟。 这意味着用户认为存在问题。

我是唯一一个患此病的人吗? 它涉及多个应用程序,对于像这样简单的实现来说也是如此。 我在一个新的空白项目中试过这个。

- (IBAction)showAlertView { [[[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil] show]; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"this is fast"); } -(IBAction)showAlert { UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"test" message:@"test" preferredStyle:UIAlertControllerStyleAlert]; [controller addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"this is slow"); }]]; [self presentViewController:controller animated:NO completion:nil]; } 

在将任何内容打印到控制台之前,单击该按钮可提供大约1秒的延迟。 警报的呈现不会延迟。

编辑:通过更接近的时间,它可能更像是700毫秒,所以不是一整秒,但对于应该是瞬间的东西仍然太长。

我知道这是一个老问题,但我遇到了同样的问题,在ViewController中添加这个问题,呈现UIAlertController为我解决了这个问题:

 - (BOOL)canBecomeFirstResponder { return YES; } 

Swift版本:

 override func canBecomeFirstResponder() -> Bool { return true } 

可悲的是,压倒一切的canBecomeFirstResponder并没有帮助我们。

帮助我们的是在显示警报之前在视图控制器中的任何可能的响应者上调用resignFirstResponder

出于某种原因,如果文本字段是第一响应者,看起来它会尝试通过视图层次结构寻找下一个响应者。 如果没有任何文本字段有焦点,则延迟消失。