uhf*_*cuz 6 xcode keyboard-events ios 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)
}
Run Code Online (Sandbox Code Playgroud)
但是使用iOS8中的新键盘,键盘能够在不关闭键盘的情况下进行更改,而我想知道如何在键盘大小更改时调用函数.谁知道?谢谢.
编辑:它现在调用帧更改但使用此代码:
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
NSLog("\(keyboardSize.height)")
}
Run Code Online (Sandbox Code Playgroud)
它返回旧的键盘高度,例如当帧变为"224.0"时它返回"253.0",好像高度没有按照调用代码的时间更新,当它变为"253.0"时它再次返回旧的高度这是"224.0"
编辑2:我使用"UIKeyboardFrameEndUserInfoKey"而不是使用"UIKeyboardFrameBeginUserInfoKey",它现在正在工作.
您需要 UIKeyboardWillChangeFrameNotification 和/或 UIKeyboardDidChangeFrameNotification。
有关所有键盘相关通知的信息,请参阅UIWindow 文档。
| 归档时间: |
|
| 查看次数: |
2464 次 |
| 最近记录: |