Search code examples
iosobjective-ckeyboardnotificationsfirst-responder

How to get the keyboard size without UINotifications IOS


I have a text field and a text view on screen. When my text view is the focused I need to show another view but if the text field is focused not show the view. I am using the UINotification methods to get the keyboard size, but they aren't fired if a text field is focused and the a text view is focused because the whole time the keyboard is shown. Get what I'm saying? So how do I get the keyboard size from somewhere else?

Also: I can't use static values because my app supports different orientations and iPhone and iPad.


Solution

  • Use delegates to get which control is currently focused.UITextViewDelgate method textViewDidBeginEditing: gets called when text view starts editing/focused or become first responder. Similarly UITextFieldDelegate method textFieldDidBeginEditing: can be used for this purpose.

    Keyboard size:

    See 'rich' answer

    Get keyboard size without UIKeyboardWillShowNotification