如何获取键盘的高度,包括Swift 4中的建议栏 [英] how to get the height of the keyboard including the suggestions bar in swift 4

查看:1132
本文介绍了如何获取键盘的高度,包括Swift 4中的建议栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过:

NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)

@objc func keyboardWillShow(notification: NSNotification) {
      if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
      let keyboardHeight : Int = Int(keyboardSize.height)
      print("keyboardHeight",keyboardHeight)
      KeyboardHeightVar = keyboardHeight
      }
}

更改以获取键盘的高度,但高度不包括建议栏. 如何获取键盘高度加上建议栏高度的值?

to change to get the height of the keyboard, but the height doesn't include the suggestions bar. How do I get the value of the keyboard height plus the suggestions bar height?

推荐答案

使用UIKeyboardFrameEndUserInfoKey而不是UIKeyboardFrameBeginUserInfoKey返回正确的键盘高度. 例如,如果键盘没有工具栏,它将返回216.0的高度.使用工具栏-260.0

Using the UIKeyboardFrameEndUserInfoKey instead of UIKeyboardFrameBeginUserInfoKey returns the correct keyboard height. For example, if the keyboard without the toolbar, it returns 216.0 height. With the toolbar - 260.0

这篇关于如何获取键盘的高度,包括Swift 4中的建议栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆