繁体   English   中英

键盘大小在swift中改变了事件?

[英]Keyboard size changed event in swift?

我知道keyboardWillShow和keyboardWillHide事件:

override public func viewWillAppear(animated: Bool) {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
    }

但是使用iOS8中的新键盘,键盘能够在不关闭键盘的情况下进行更改,而我想知道如何在键盘大小更改时调用函数。 谁知道? 谢谢。

编辑:它现在调用帧更改但使用此代码:

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
            NSLog("\(keyboardSize.height)")
        }

它返回旧的键盘高度,例如当帧变为“224.0”时它返回“253.0”,好像高度没有按照调用代码的时间更新,当它变为“253.0”时它再次返回旧的高度这是“224.0”

编辑2:我使用“UIKeyboardFrameEndUserInfoKey”而不是使用“UIKeyboardFrameBeginUserInfoKey”,它现在正在工作。

您想要UIKeyboardWillChangeFrameNotification和/或UIKeyboardDidChangeFrameNotification。

有关所有与键盘相关的通知,请参阅UIWindow文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM