1

こんにちは、 の問題に直面していUITextViewます。

私のアプリでは、ポートレートとランドスケープの両方をサポートする必要があります。

だから私は自分のアプリに追加し、次のコードでキーボードが表示されたときUITextViewのフレームのサイズを変更しました.UITextViewUITextViewUITextView

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

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

- (void)moveTextViewForKeyboard:(NSNotification*)notification up:(BOOL)up {
    NSDictionary *userInfo = [notification userInfo];
    NSTimeInterval animationDuration;
    UIViewAnimationCurve animationCurve;
    CGRect keyboardRect;

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
    animationDuration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    keyboardRect = [self.view convertRect:keyboardRect fromView:nil];

    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:animationCurve];

    if (up == YES)
    {
        CGFloat keyboardTop = keyboardRect.origin.y;
        CGRect newTextViewFrame = self.txtView.frame;
        newTextViewFrame.size.height = keyboardTop - self.txtView.frame.origin.y - 10;
        self.txtView.frame = newTextViewFrame;
    }

    else
    {
        self.txtView.frame = originalCGRect;
    }

    [UIView commitAnimations];
}

キーボードが表示され、UITextViewもうカバーされていない場合は問題ありません。ただし、横向きに回転すると、UITextViewフレームが正しくなくなり、キーボードを非表示にしても、小さいサイズのままで、ビューに収まりません。

ここに画像の説明を入力

ここに画像の説明を入力

どうすればその問題を解決できますか?

私を助けてください。

4

1 に答える 1

1

自動サイズ変更マスクを試してみてください

これを試してみてください。

于 2013-07-18T10:22:07.303 に答える