[英]iOS 9 - Keyboard pops up after UIAlertView dismissed
I have a strange visual bug that only affects iOS 9 devices: 我有一个奇怪的视觉错误,只影响iOS 9设备:
My app's login UIViewController
runs off and gets an OAuth token when you hit the button, much like you'd expect. 我的应用程序的登录
UIViewController
会在您按下按钮时运行并获取OAuth令牌,就像您期望的那样。 If the response from my API returns a specific status code, I pop up a UIAlertView
saying they need to reset their password (this is if they've been flagged as such on the server end). 如果来自我的API的响应返回一个特定的状态代码,我弹出一个
UIAlertView
说他们需要重置他们的密码(如果他们在服务器端被标记为这样)。 The email and password fields for login resignFirstResponder
once you hit the button, standard stuff. 登录
resignFirstResponder
的电子邮件和密码字段,一旦你按下按钮,标准的东西。
On iOS 9 only, if you hit the reset path, the second you tap OK on that alert view, the keyboard pops back up, for maybe 800ms, then dismisses again. 仅在iOS 9上,如果您点击重置路径,则在该警报视图上点按“确定”,键盘会弹回,可能会持续800毫秒,然后再次解除。 It's almost as if something was queued to present it, but the presence of the alert blocked it until you hit OK – it's absolutely instantaneous after hitting okay on the alert.
这几乎就好像有什么东西排队等候呈现它,但警报的存在阻止了它直到你点击确定 - 它在警报点击之后绝对是瞬间的。
It seems a really tricky one to debug. 调试似乎非常棘手。 I've added symbolic breakpoints to
becomeFirstResponder
and it isn't called anywhere near this process occurring. 我已经将符号断点添加到了
becomeFirstResponder
并且在此过程发生的任何地方都没有调用它。
Any other ideas for how I can look at debugging / fixing this? 有关如何查看调试/修复此问题的其他任何想法? It doesn't affect iOS 7 and iOS 8, only iOS 9.
它不会影响iOS 7和iOS 8,只会影响iOS 9。
I faced this problem about 30 minutes ago. 大约30分钟前我遇到了这个问题。
The UIAlertView has been deprecated since iOS9 was released. 自iOS9发布以来,UIAlertView已被弃用。
We solved this issue by using the UIAlertController, like this: 我们使用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];
This should fix your problem. 这应该可以解决您的问题。
If animated = YES, you may get the same issue as before. 如果动画= YES,您可能会遇到与以前相同的问题。 This is a bug with iOS9.
这是iOS9的一个错误。
Let me know how it goes, and if this fixes your problem. 让我知道它是怎么回事,如果这解决了你的问题。
Here is an extension to handle this in swift 3 这是一个在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)
}
}
}
The key is to hide the keyboard and present the controller in the main queue. 关键是隐藏键盘并将控制器显示在主队列中。
Usage 用法
presentOk(with: "My app title", and: "this is the alert message", handler: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.