KEEP keyboard ON when UIAlertcontroller is presented in Swift?(Swift 中显示 UIAlertcontroller 时保持键盘打开?)
问题描述
当警报弹出时,键盘被关闭.我到处寻找,但没有找到保持键盘可见的解决方案.当警报出现时,文本字段似乎会自动退出第一响应者,因为警报以模态方式出现.如何将键盘保持在此警报后面,这意味着即使无法进行交互,文本字段仍在编辑?
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 时保持键盘打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swift 中显示 UIAlertcontroller 时保持键盘打开?


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01