【发布时间】:2016-05-03 21:10:29
【问题描述】:
我有一个视图,我需要始终显示键盘,但这并不容易,因为每当警报视图显示它关闭我的键盘时,我都会在所述视图中以模态方式呈现另一个视图。
所以我的解决方法是使用假键盘作为图像视图,它现在有键盘图像我可以随时显示我的键盘,但我想删除键盘显示和隐藏在我的假键盘上的过渡。
我找到了this,但它不适用于 ios9
【问题讨论】:
我有一个视图,我需要始终显示键盘,但这并不容易,因为每当警报视图显示它关闭我的键盘时,我都会在所述视图中以模态方式呈现另一个视图。
所以我的解决方法是使用假键盘作为图像视图,它现在有键盘图像我可以随时显示我的键盘,但我想删除键盘显示和隐藏在我的假键盘上的过渡。
我找到了this,但它不适用于 ios9
【问题讨论】:
如果我的键盘出现,这对我有用:
private func presentAlert(alertController: UIAlertController) {
dispatch_async(dispatch_get_main_queue(), {
guard let topViewController = UIApplication.sharedApplication().windows.last!.rootViewController else {
return
}
topViewController.presentViewController(alertController, animated:true,
completion:nil)
})
}
private func createAlert(title: String, message: String) -> UIAlertController {
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction: UIAlertAction = UIAlertAction(title: "OK", style: .Cancel) {
action -> Void in
// Do something?
}
alertController.addAction(cancelAction)
return alertController
}
然后你可以像这样调用警报:
presentAlert(createAlert("Title", message: "Your message here"))
这是它的截图:
【讨论】: