[英]IOS what method is called when keyboard pops up
我正在制作自定義的IOS鍵盤。 我想知道每當用戶選擇鍵盤時是否會調用任何方法,從而使它在屏幕上彈出。 這是因為我想在鍵盤彈出時運行一些代碼。
通知: UIKeyboardDidShowNotification
被調用。 您可以為此方法創建一個觀察者,該觀察者為兩個操作觸發一個函數,如下所示:
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardDidShow:"), name:UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardDidHide:"), name:UIKeyboardWillHideNotification, object: nil)
func keyboardDidShow(notification: NSNotification) {
print("Keyboard shown")
}
func keyboardDidHide(notification: NSNotification) {
print("Keyboard hidden")
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.