当警报弹出时,键盘被关闭.我到处寻找,但没有找到保持键盘可见的解决方案.当警报出现时,文本字段似乎会自动退出第一响应者,因为警报以模态方式出现.如何将键盘保持在此警报后面,这意味着即使无法进行交互,文本字段仍在编辑?
When the alert pops up the keyboard is dismissed. I have looked everywhere but did not find solutions to keep the keyboard visible. When alert is presented the textfield seems to resign first responder automatically as the alert is presented modally. How is it possible to keep the keyboard behind this alert which means the textfield still editing even if no interaction will be possible ?
这个解决方案对我有用:
This solution works for me:
let rootViewController: UIViewController =
UIApplication.sharedApplication().windows.lastObject.rootViewController!!
rootViewController.presentViewController(alert, animated: true, completion: nil)
<小时>
@galambalazs 它起作用的原因是:
您可以抓取当前最高窗口级别的窗口,并将您的 View Controller 显示在该 Window 中(使其成为顶部 View Controller在顶部窗口).
You can grab the window with the current highest window level and present your View Controller inside that Window (making it the top View Controller in the top Window).
UIApplication.sharedApplication().windows
数组中的窗口按窗口级别从后到前排序;
因此,数组中的最后一个窗口位于所有其他应用程序窗口的顶部.
UIApplication.sharedApplication().windows
The windows in the array are ordered from back to front by window level;
thus, the last window in the array is on top of all other app windows.
您可能还需要设置该窗口的 tintColor,使其与您的应用程序全局 tintColor 匹配.
Also you might want to set the tintColor of that window so that it matches your apps global tintColor.
UIWindow *topWindow = [UIApplication sharedApplication].windows.lastObject;
// we inherit the main window's tintColor because topWindow may not have the same
topWindow.tintColor = [UIApplication sharedApplication].delegate.window.tintColor;
这篇关于Swift 中显示 UIAlertcontroller 时保持键盘打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!