7

I have an application in which I have to scroll up in case of the keyboard showing. to get the keyboard size, I'm registering the UIKeyboardWillShowNotification event like so:

   [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWillShow:)
     name:UIKeyboardWillShowNotification
     object:self.view.window]

This does work, the problem is, it is being called after the textFieldDidBeginEditing was called. So, I can't get the actual keyboard size, but only after the field is already in edit mode, which defeats the whole purpose of registering this event on the first place. I'm sure I've called the UIKeyboardWillShowNotification and not the UIKeyboardDidShowNotification, although switching these two yield the same results: first call was made to the delegate method and only then to the notification method. Any idea on how to turn this around? Currently I'm hard coding the size, which is very bad practice...

4

5 に答える 5

2

GitHub リポジトリを提案できますか

https://github.com/hackiftekhar/IQKeyboardManager

于 2014-01-19T16:09:10.863 に答える
0

古い質問ですが、今日同じ問題に遭遇しました。キーボードのサイズをハードコードする必要のない、ちょっとした「汚い」回避策を作成しました。私は単純にviewDidAppearで次のことを行いました(注意 - Swift):

 override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.infoTextField.becomeFirstResponder()
    self.infoTextField.resignFirstResponder()
}

これによりUIKeyboardWillShowNotificationがトリガーされ、通知からキーボード サイズを取得してプロパティに保存できます。これが誰かの役に立てば幸いです。私の場合はうまくいきました。

于 2016-02-03T15:45:58.297 に答える