![](/img/trans.png)
[英]Keyboard pops up after UIAlertView is dismissed on iOS 8.3 for iPad
[英]iOS 9 - Keyboard pops up after UIAlertView dismissed
我有一个奇怪的视觉错误,只影响iOS 9设备:
我的应用程序的登录UIViewController
会在您按下按钮时运行并获取OAuth令牌,就像您期望的那样。 如果来自我的API的响应返回一个特定的状态代码,我弹出一个UIAlertView
说他们需要重置他们的密码(如果他们在服务器端被标记为这样)。 登录resignFirstResponder
的电子邮件和密码字段,一旦你按下按钮,标准的东西。
仅在iOS 9上,如果您点击重置路径,则在该警报视图上点按“确定”,键盘会弹回,可能会持续800毫秒,然后再次解除。 这几乎就好像有什么东西排队等候呈现它,但警报的存在阻止了它直到你点击确定 - 它在警报点击之后绝对是瞬间的。
调试似乎非常棘手。 我已经将符号断点添加到了becomeFirstResponder
并且在此过程发生的任何地方都没有调用它。
有关如何查看调试/修复此问题的其他任何想法? 它不会影响iOS 7和iOS 8,只会影响iOS 9。
大约30分钟前我遇到了这个问题。
自iOS9发布以来,UIAlertView已被弃用。
我们使用UIAlertController解决了这个问题,如下所示:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert Title!" message:@"This is an alert message." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
[self presentViewController:alertController animated:NO completion:nil];
这应该可以解决您的问题。
如果动画= YES,您可能会遇到与以前相同的问题。 这是iOS9的一个错误。
让我知道它是怎么回事,如果这解决了你的问题。
这是一个在swift 3中处理这个问题的扩展
extension UIViewController {
func presentOk(with title: String, and message: String, handler: ((UIAlertAction) -> Void)?) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: handler))
OperationQueue.main.addOperation {
self.view.endEditing(true)
self.present(alert, animated: true, completion: nil)
}
}
}
关键是隐藏键盘并将控制器显示在主队列中。
用法
presentOk(with: "My app title", and: "this is the alert message", handler: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.