我试图在键盘显示和消失时运行一个函数,并具有以下代码:
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(ViewController.keyBoardUp(Notification :)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
Run Code Online (Sandbox Code Playgroud)
以下功能keyBoardUp:
func keyBoardUp( Notification: NSNotification){
print("HELLO")
}
Run Code Online (Sandbox Code Playgroud)
但是,当键盘显示时,该功能不会打印到控制台.非常感谢帮助