How to get keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard?
Asked Answered
P

1

6

How to get a keyboard size to resize UITextView and how to use UIKeyboardFrameEndUserInfoKey with Japanese keyboard? The following code to resize UITextView works good on a standard keyboard. But doesn't work with Japanese. How to fix it?

- (void)keyboardWillShow:(NSNotification *)aNotification {
    [self moveTextViewForKeyboard:aNotification up:YES];
}

- (void)keyboardWillHide:(NSNotification *)aNotification {
    [self moveTextViewForKeyboard:aNotification up:NO]; 
}

- (void) moveTextViewForKeyboard:(NSNotification*)aNotification up: (BOOL) up
{
    NSDictionary* userInfo = [aNotification userInfo];

    // Get animation info from userInfo
    NSTimeInterval animationDuration;
    UIViewAnimationCurve animationCurve;

    CGRect keyboardEndFrame;

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];

    // Animate up or down
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:animationCurve];

    CGRect newFrame = textView.frame;
    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];

    newFrame.size.height -= keyboardFrame.size.height * (up? 1 : -1);
    textView.frame = newFrame;

    [UIView commitAnimations];
}

Thanks a lot for the help!

Prostration answered 16/12, 2011 at 22:19 Comment(0)
P
6

The correct fragment of the code:

CGRect newFrame = editSource.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
keyboardFrame.size.height -= tabBarController.tabBar.frame.size.height;
if (up) {
    editHeight = newFrame.size.height;
    newFrame.size.height -= keyboardFrame.size.height;
} else {
    newFrame.size.height = editHeight;
}
editSource.frame = newFrame;

WARNIGN!

The method is obsolete. The correct answer is located here: How can I add support for Chinese keyboard with UITextView on iOS 7?

Prostration answered 19/12, 2011 at 4:39 Comment(1)
This method doesn't works correctly at least on iOS 7.Prostration

© 2022 - 2024 — McMap. All rights reserved.