2

I followed the instructions here to adjust my view with the iOS keyboard. https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

This doesn't work with a hardware keyboard. When a text view is active the iOS keyboard is not shown but the example code still returns the full height of the keyboard. In my case just the input accessory view is shown on the screen.

How do I detect this case and adjust my view for only the input accessory view?

Berry Blue
  • 15,330
  • 18
  • 62
  • 113
  • Possible duplicate of [How can I detect if an external keyboard is present on an iPad?](http://stackoverflow.com/questions/2893267/how-can-i-detect-if-an-external-keyboard-is-present-on-an-ipad) – Rivera Apr 11 '16 at 15:26

2 Answers2

0

You can intersect the keyboard's frame with the current window as in my answer here https://stackoverflow.com/a/36553555/1049134.

Community
  • 1
  • 1
Rivera
  • 10,792
  • 3
  • 58
  • 102
0

Came across the same issue. Looks like the iOS keyboard is completely instantiated and just moved out of the view partial when a hardware keyboard is attached. Therefore the size of the keyboard is right. It is just not completely shown.

After examining the notifications I solved it with calculating the visible keyboard height myself. In my example I am listening to UIKeyboardWillShowNotification, UIKeyboardWillChangeFrameNotification and UIKeyboardWillHideNotification.

-(void)keyboardMessage:(NSNotification*)notification {
        NSDictionary *userInfo = notification.userInfo;
        CGFloat duration = [userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
        NSValue *value = userInfo[@"UIKeyboardFrameEndUserInfoKey"];
        CGRect frame = [value CGRectValue];
        [UIView animateWithDuration:duration animations:^{
            self.lowerContraint.constant = self.view.frame.size.height - frame.origin.y;;
            [self.view needsUpdateConstraints];
            [self.view layoutIfNeeded];
        }];
    }
Helge Becker
  • 3,219
  • 1
  • 20
  • 33