[英]Keyboard size changed event in swift?
I am aware of the keyboardWillShow and the keyboardWillHide events by: 我知道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)
}
But with the new keyboards in iOS8 the keyboard is able to change without dismissing the keyboard and I was wondering how to call a function on keyboard size change. 但是使用iOS8中的新键盘,键盘能够在不关闭键盘的情况下进行更改,而我想知道如何在键盘大小更改时调用函数。 Anyone know?
谁知道? Thanks.
谢谢。
Edit: It is now calling on frame change but using this code: 编辑:它现在调用帧更改但使用此代码:
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
NSLog("\(keyboardSize.height)")
}
It returns the old keyboard height for example when the frame changes to "224.0" it returns "253.0" as if the height has not updated by time the code is called, and when it goes have to "253.0" it returns the old height again which is "224.0" 它返回旧的键盘高度,例如当帧变为“224.0”时它返回“253.0”,好像高度没有按照调用代码的时间更新,当它变为“253.0”时它再次返回旧的高度这是“224.0”
Edit 2: Instead of using "UIKeyboardFrameBeginUserInfoKey", I used "UIKeyboardFrameEndUserInfoKey" and it is now working. 编辑2:我使用“UIKeyboardFrameEndUserInfoKey”而不是使用“UIKeyboardFrameBeginUserInfoKey”,它现在正在工作。
You want UIKeyboardWillChangeFrameNotification and/or UIKeyboardDidChangeFrameNotification. 您想要UIKeyboardWillChangeFrameNotification和/或UIKeyboardDidChangeFrameNotification。
See the documentation of UIWindow for all of the keyboard related notifications. 有关所有与键盘相关的通知,请参阅UIWindow的文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.