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 时保持键盘打开?
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
