同时显示 UIAlertView 和键盘

Show UIAlertView and keyboard simultaneously

看起来 iOS 8 有一个错误,其中带有文本输入的警报不显示键盘。我试过了 this hack.

hack 的问题是首先出现警报,然后才出现键盘。这会导致 "jump up" 的警报使键盘成为 space。

如何让 UIAlertView 带有文本输入,键盘立即出现?

(注意:我想要的示例,转到语音备忘录,录制新的备忘录,保存,系统会提示您输入带有文本输入的 UIAlertView 的名称。有, 键盘与 UIAlertView 同时出现。)

我不确定这是否能完美解决键盘和alertView同时出现的问题。但我建议您使用较新的 api。我将此作为答案发布,因为很难将代码放入评论中。

由于某些原因 UIAlertView 已在 iOS 8 中弃用。您应该使用 UIAlertController 风格 UIAlertControllerStyleAlert 而不是使用 UIAlertView。展示它然后打开键盘。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:yourTitle message:yourMessage preferredStyle:UIAlertControllerStyleAlert];

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

由于警报现在显示为 UIViewController,因此键盘不会将警报框向上移动。

//ctrl+k出现键盘和ios8键盘同时出现问题就解决了...

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"" message:@"Registration Successfully" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){

                            // [self.view endEditing:YES];
                            // [self.navigationController popToRootViewControllerAnimated:YES];

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