【问题标题】:How to remove UIKeyboard animation both in sliding up(showing) and sliding down(hiding)? -IOS9 Swift如何在向上滑动(显示)和向下滑动(隐藏)时删除 UIKeyboard 动画? -IOS9 斯威夫特
【发布时间】:2016-05-03 21:10:29
【问题描述】:

我有一个视图,我需要始终显示键盘,但这并不容易,因为每当警报视图显示它关闭我的键盘时,我都会在所述视图中以模态方式呈现另一个视图。

所以我的解决方法是使用假键盘作为图像视图,它现在有键盘图像我可以随时显示我的键盘,但我想删除键盘显示和隐藏在我的假键盘上的过渡。

我找到了this,但它不适用于 ios9

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    如果我的键盘出现,这对我有用:

    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"))
    

    这是它的截图:

    【讨论】:

    • 太棒了!但现在我很困惑为什么它第一次不起作用..谢谢男人
    • 我认为是缺少 dispatch_async(dispatch_get_main_queue)。没问题!很高兴它对你有用。
    • 哦,我记得,我实际上并没有使用 alertController 我正在使用 viewController 并修改了 framesize 看起来像警报。在这种情况下,它可以正常显示视图,但它隐藏了键盘。但如果我只使用 alertController 它就可以了。仍然需要使用 viewController
    猜你喜欢
    • 2018-10-20
    • 2019-06-14
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多