How to write Keyboard notifications in Swift 3

前端 未结 10 1571
清歌不尽
清歌不尽 2020-12-08 10:37

I\'m trying to update this code to swift 3:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(\"keyboardWillShow:\"), name: UIKeyboar         


        
10条回答
  •  温柔的废话
    2020-12-08 11:22

    For Swift 4.2 .UIKeyboardWillShow is renamed to UIResponder.keyboardWillShowNotification and .UIKeyboardWillHide is renamed to UIResponder.keyboardWillHideNotification

     NotificationCenter.default.addObserver(self, selector: #selector(NameOfSelector), name: UIResponder.keyboardWillShowNotification , object: nil)
     NotificationCenter.default.addObserver(self, selector: #selector(NameOfSelector), name: UIResponder.keyboardWillHideNotification , object: nil)
    
       @objc func NameOfSelector() {
           //Actions when notification is received
        }
    

提交回复
热议问题