UIKeyboardDidShowNotification called multiple times, and sometimes with incorrect keyboard dimensions

前端 未结 4 780
醉话见心
醉话见心 2021-02-07 08:12

I am trying to move a UITextView above the keyboard whenever the keyboard appears/changes. Let\'s say I have the English keyboard displaying and then switch directly to the Chin

4条回答
  •  一个人的身影
    2021-02-07 08:46

    The primary reason is that the your notification is invoked multiple times. For example, in swift, if you had the NSNotificationCenter.defaultCenter().addObserver(xx"keyboardWillShow"xx) inside viewWillAppear method and if you are going back and forth between the view then it will result in having multiple observer of the same "keyboardWillShow". Instead you should consider moving the addObserver call to "viewDidLoad()" method. Alternatively you can register/deregister observer when the view appears/disappears.

提交回复
热议问题