当UIAlertcontroller在Swift中呈现时,KEEP键盘是否打开? [英] KEEP keyboard ON when UIAlertcontroller is presented in Swift?

查看:152
本文介绍了当UIAlertcontroller在Swift中呈现时,KEEP键盘是否打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当弹出警报时,键盘将被解除。我到处寻找,但没有找到保持键盘可见的解决方案。当提示警报时,文本字段似乎会自动重新响应第一响应者,因为警报是以模态方式呈现的。如何将键盘保持在此警报之下,这意味着即使没有可能的交互,文本字段仍在编辑?

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 ?

推荐答案

这个解决方案适合我:

let rootViewController: UIViewController = 
    UIApplication.sharedApplication().windows.lastObject.rootViewController!!
rootViewController.presentViewController(alert, animated: true, completion: nil)






由@galambalazs编辑:它起作用的原因是:

你可以抓住当前的窗口最高窗口级别并在 Window 中显示 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,使其与您的应用程序global 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;

这篇关于当UIAlertcontroller在Swift中呈现时,KEEP键盘是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆