swift2.0 动态获取键盘高度 Get KeyboardHeight

前端之家收集整理的这篇文章主要介绍了swift2.0 动态获取键盘高度 Get KeyboardHeight前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. 列表内容

监听键盘起落 下面是可以监听到得四种状态

UIKeyboardWillShowNotification: String
UIKeyboardDidShowNotification: String
UIKeyboardWillHideNotification: String
UIKeyboardDidHideNotification: String

  1. NSNotificationCenter.defaultCenter().addObserver(self,selector: "keyboardWillAppear:",name: UIKeyboardWillShowNotification,object: nil)
  2.  
  3. NSNotificationCenter.defaultCenter().addObserver(self,selector: "keyboardWillDisappear:",name:UIKeyboardWillHideNotification,object: nil)
  1. func keyboardWillAppear(notification: NSNotification) {
  2.  
  3. // 获取键盘信息
  4. let keyboardinfo = notification.userInfo![UIKeyboardFrameBeginUserInfoKey]
  5.  
  6. let keyboardheight:CGFloat = (keyboardinfo?.CGRectValue.size.height)!
  7.  
  8. print("键盘弹起")
  9.  
  10. print(keyboardheight)
  11.  
  12. }
  13.  
  14. func keyboardWillDisappear(notification:NSNotification){
  15.  
  16. print("键盘落下")
  17. }

猜你在找的Swift相关文章