Get keyboard size without UIKeyboardWillShowNotification

Viewed 12481

I want to get the size of the keyboard without using the keyboard notifications available. The reason is I have several text field on the view and I don't need to resize the view for all of them, as I have seen in nearly every example. I just need to resize the view for some of the text fields/views that will be behind the keyboard when editing. So I'm using textFieldDidBeginEditing and textFieldDidEndEditing methods, because here I know what textfield is being edited. Another problem is that even if I subscribe to the keyboard notifications the UIKeyboardWillShowNotification is fired after textFieldDidBeginEditing so I cannot get the keyboard size on the first activation. I assume no information is provided from the keyboard notification functions where the actual text field or view is abailable.

The following code works but I need the keyboard size:

- (void) textFieldDidBeginEditing:(UITextField *) textField {
  if ([theControls containsObject: textField]) {
    [UIView beginAnimations: @"szar" context: nil];
    [UIView setAnimationDuration:0.3];
    self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, -216);
    [UIView commitAnimations];
  }
}

- (void) textFieldDidEndEditing:(UITextField *) textField {
  if ([theControls containsObject: textField]) {
    [UIView beginAnimations: @"szar" context: nil];
    [UIView setAnimationDuration:0.3];
    self.view.transform = CGAffineTransformTranslate(self.view.transform, 0, +216);
    [UIView commitAnimations];
  }
}
1 Answers
Related