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

时间:2014-11-19 03:38:48

标签: ios xcode swift keyboard-events

我通过以下方式了解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: 我没有使用" UIKeyboardFrameBeginUserInfoKey"而是使用" UIKeyboardFrameEndUserInfoKey"它现在正在运作。

1 个答案:

答案 0 :(得分:3)

您想要UIKeyboardWillChangeFrameNotification和/或UIKeyboardDidChangeFrameNotification。

有关所有与键盘相关的通知,请参阅documentation of UIWindow