当UIAlertcontroller在Swift中呈现时,KEEP键盘是否打开?

编程入门 行业动态 更新时间:2024-10-27 03:43:08
本文介绍了当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键盘是否打开?

本文发布于:2023-11-27 19:33:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键盘   UIAlertcontroller   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!