//通知中心
let center = NSNotificationCenter.defaultCenter()
//当键盘将要弹起时候执行方法UIKeyboardWillShowNotification
center.addObserver(self, selector: #selector(willShow(_:)), name: UIKeyboardDidHideNotification, object: nibName)
//键盘将要收起时执行方法UIKeyboardWillHideNotification
center.addObserver(self, selector: #selector(willHide(_:)), name: UIKeyboardWillHideNotification, object: nibName)
//键盘出现的方法,此处比较难得地方是如何获取通知里的内容,
func willShow(notice : NSNotification) {
//通知里的内容
let userInfo = notice.userInfo as NSDictionary!
let aValue = userInfo.objectForKey(UIKeyboardFrameEndUserInfoKey)
let keyboardRect = aValue?.CGRectValue()
//键盘的高度
let keyBoardHeight = keyboardRect?.size.height
}
//键盘收起的方法
func willHide(notice : NSNotification){
}