在斯威夫特:
您可以通过订阅UIKeyboardWillShowNotification通知获得键盘高度。 (假设你想知道在显示之前会有什么高度)。
这样的事情
NSNotificationCenter.defaultCenter().addObserver(self,selector: "keyboardWillShow:",name: UIKeyboardWillShowNotification,object: nil)
那么你可以在这样的功能中访问高度:
func keyboardWillShow(notification:NSNotification) { let userInfo:NSDictionary = notification.userInfo! let keyboardFrame:NSValue = userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue let keyboardRectangle = keyboardFrame.CGRectValue() let keyboardHeight = keyboardRectangle.height }