简体   繁体   English

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

[英]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.

相关问题 不使用键盘快速键检测何时更改UITextField - Detect when UITextField is changed not using the keyboard swift 使用建议栏获取键盘尺寸 swift - Get keyboard size with suggestion bar swift Codenameone:装上键盘后,文本字段的大小和格式被更改 - Codenameone: Textfield size and format getting changed after keyboard appered 如果使用多任务处理时视图大小发生变化,如何设置通知 | 斯威夫特 - How to set Notification if view size changed when using multitasking | Swift ios - 如何在swift ios xcode中检测UIView大小何时更改? - How to detect when UIView size is changed in swift ios xcode? 使用Swift或Objective-C在iOS中以编程方式获取键盘按键的大小 - Get size of keyboard keys programmatically in iOS with Swift or Objective-C 如何使用Swift在iOS中检测多行键盘粘贴事件? - How can I detect a multiline keyboard paste event in iOS with Swift? 从XCode 7和Swift 2.2移至XCode 8 Swift 2.3:帧大小已更改 - Move From XCode 7 and Swift 2.2 to XCode 8 Swift 2.3 : frame size changed Swift UIButton 在本地化过程中改变大小,但边界数据没有改变 - Swift UIButton changes size during localization but the bounds data doesn't get changed 隐藏具有已编辑更改的TextField的键盘 - hide keyboard for TextField with Edited Changed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM