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 时保持键盘打开?
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01