【问题标题】:iOS 8 Swift : How to keep the keyboard displayed when the UIAlercontroller is presented modally?iOS 8 Swift:当 UIAlercontroller 模态显示时如何保持键盘显示?
【发布时间】:2015-04-18 00:15:34
【问题描述】:

上下文非常简单,有一个带有文本字段的 UIViewcontroller 用于输入电话号码。文本字段处于使用键盘的编辑模式。

输入数字后,用户可以点击显示警报控制器的按钮。由于警报以模态方式呈现,它覆盖了 UIViewcontroller 并移除了键盘,因此不再启用编辑。

所以我的问题是,应该怎么做才能让键盘显示在警报后面?

【问题讨论】:

标签: ios swift keyboard uitextfield uialertcontroller


【解决方案1】:

我相信你做不到。最好尝试制作允许通过手势的自定义警报。

【讨论】:

  • 感谢 Amresh 的回答。我可能不够精确。我只希望在警报后面的文本字段(编辑模式)中显示键盘和光标。我不是在寻找有关文本字段的任何用户交互。
  • 我以前从未尝试过,但可能会从 canResignFirstResponder 返回 NO,因为当前文本字段可以解决问题
【解决方案2】:

这个解决方案有效

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

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    相关资源
    最近更新 更多