swift获取键盘高度
Posted 托雷斯也学iOS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift获取键盘高度相关的知识,希望对你有一定的参考价值。
- 列表内容
监听键盘起落 下面是可以监听到得四种状态
UIKeyboardWillShowNotification: String
UIKeyboardDidShowNotification: String
UIKeyboardWillHideNotification: String
UIKeyboardDidHideNotification: String
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillAppear:", name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillDisappear:", name:UIKeyboardWillHideNotification, object: nil)
func keyboardWillAppear(notification: NSNotification) { // 获取键盘信息 let keyboardinfo = notification.userInfo![UIKeyboardFrameBeginUserInfoKey] let keyboardheight:CGFloat = (keyboardinfo?.CGRectValue.size.height)! print("键盘弹起") print(keyboardheight) } func keyboardWillDisappear(notification:NSNotification){ print("键盘落下") }
以上是关于swift获取键盘高度的主要内容,如果未能解决你的问题,请参考以下文章