I'm using the method described by Josh in this question to add a toolbar to the top of the iPhone's keyboard. Basically, the idea is:
- Add the view controller as an observer for the notifications
UIKeyboardWillShowNotification
andUIKeyboardWillHideNotification
in its initialization method - Whenever those notifications are posted, animate a toolbar onto/off of the screen along with the keyboard
I also have multiple UITextFields on the screen, all of which become the first responder when selected for editing and resign first responder when editing is complete (either the user taps another text field, off any text field, or presses "Done" on the keyboard - I have textFieldShouldReturn:
overridden to resignFirstResponder
).
I'm having a problem, though, since the notifications are being posted every time I switch between text fields. For example, if a user is editing text field A, then finishes with it and taps text field B, A resigns first responder and B becomes first responder. However, this also posts both the "will show" and "will hide" notifications to my view controller.
The end result of all this is that while the toolbar appears with the keyboard for the first text field, and disappears with the keyboard for the last text field, it appears to slide into and back out of the keyboard every time the user switches between text fields.
Is there a way to only respond to the "will {show,hide}" notifications if the keyboard is actually going to show or hide? Put another way, how can I ignore notifications that will not result in a change in the keyboard's visible state?