1

I'm debugging someone else's code - sorry I have very limited Objective-C experience.

#pragma mark - Keyboard events

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    NSLog(@"Keyboard a Notification user Info %@", info);

    printf("keyboardWasShown \\\\\\\\\\\\\\\\\\\\\n");
    NSLog(@"textInputView: y: (%.f), height: (%.f), kbHeight: (%.f)",
        textInputView.frame.origin.y, textInputView.frame.size.height, kbSize.height);

    [UIView animateWithDuration:2.0f animations:^{
        if (keyboardNewLine){
            bubbleTableFrame = originalBubbleTableFrame;
        }
        CGRect frame = originalTextViewFrame;
        int difference = 0;

        if (IsIphone5){
                difference = -42;
                frame.origin.y -= kbSize.height + difference;

        } else {
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
                difference = 42;
                frame.origin.y -= kbSize.height + difference;
            } else {
                frame.origin.y -= kbSize.height + 110;
                difference = 42;
            }
        }
        textInputView.frame = frame;

        frame = bubbleTableFrame;
        frame.size.height -= kbSize.height + difference;
        bubbleTable.frame = frame;
    }];

    NSLog(@"textInputView: y: (%.f), height: (%.f), kbHeight: (%.f)",
          textInputView.frame.origin.y, textInputView.frame.size.height, kbSize.height);
    printf("keyboardWasShown //////////\n");

    [bubbleTable scrollBubbleViewToBottomAnimated:YES];
}

When I tap the text input field to bring up the keyboard, the field should move up to just above the keyboard - sometimes. It all depends on the which keyboard is loading first.

  1. The text field without keyboard:

https://dl.dropboxusercontent.com/u/674780/img/stackoverflow/1.png

  1. After tapping the text field, I expect:

https://dl.dropboxusercontent.com/u/674780/img/stackoverflow/2.png

  1. However the text field stays at the bottom of the screen, leaving only the placeholder:

enter image description here

  1. Strange enough, if I drag down the QuickType row, the text field suddenly appears!

enter image description here

  1. But if I exit from this view and come back afterwards, once again the text field is stuck at the bottom (and guess what, it jumps up if I drag UP the QuickType row):

enter image description here

  1. Switching to another keyboard (input method) by tapping the globe icon always helps to bring up the text field:

enter image description here

  1. It seems that third-party keyboards are not affected:

enter image description here

You can see that I keep monitoring textInputView.frame.origin.y to see what goes wrong. It changes from 472 (no keyboard) to 261 (English keyboard) but the text field simply doesn't go up.

I don't think it is behind the placeholder (if any) because when I tap the white area beside the bubbles, the keyboard moves down and unveils the text field stuck at the bottom.

Someone suggested adding setNeedsDisplay, setNeedsLayout, etc. but none helped.

Thanks in advance.

vk.edward.li
  • 1,899
  • 16
  • 22

1 Answers1

0

Eventually I turned off Auto Layout as suggested by someone: https://www.facebook.com/groups/cocoahk/permalink/1104922892867587/

It worked. Though I needed to adjust the positions of all other objects.