1

您好,我面临一个问题UITextView

在我的应用程序中,我需要同时支持纵向和横向。

所以我添加UITextView到我的应用程序中并使用以下代码调整键盘出现时的框架,UITextView因为当键盘出现时,UITextView它在键盘后面,我看不到我写的内容UITextView

- (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框架不再正确,而且当我隐藏键盘时,它仍然像小尺寸一样,不适合 View。

在此处输入图像描述

在此处输入图像描述

我该如何解决这个问题?

请帮我。

4

1 回答 1

1

你能试试看自动调整蒙版试试这个吗

试试这个希望对你有帮助......

于 2013-07-18T10:22:07.303 回答