解决方法
添加两个观察者
NSNotificationCenter.defaultCenter().addObserver(self,selector: "keyboardVisible:",name: UIKeyboardDidShowNotification,object: nil) NSNotificationCenter.defaultCenter().addObserver(self,selector: "keyboardHidden:",name: UIKeyboardDidHideNotification,object: nil) func keyboardVisible(notif: NSNotification) { print("keyboardVisible") } func keyboardHidden(notif: NSNotification) { print("keyboardHidden") }