键盘出现时如何使UITextView可滚动?

时间:2012-12-04 11:05:36

标签: iphone objective-c keyboard scroll uitextview

我想知道如何在编辑时UITextView滚动它?当用户想要编辑它时,键盘显示但是UITextView不再可滚动。所以键盘后面的所有文字都不可见。

2 个答案:

答案 0 :(得分:4)

您可以减小尺寸,如果出现在keyBoard上的textView

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    CGRect frame = txtAddNote.frame;
    frame.size.height = 150; //Decrease your textView height at this time
    txtAddNote.frame = frame;
}
-(IBAction)DoneBarBtnPress:(id)sender
{
    CGRect frame = txtAddNote.frame;
    frame.size.height = 212; //Original Size of textView
    txtAddNote.frame = frame;

    //Keyboard dismiss 
    [self.view endEditing:YES];
}

答案 1 :(得分:1)

只需在UITextView开始编辑时滚动视图..

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    self.view.frame = CGRectMake(self.view.frame.origin.x, -160, self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];

}

并在endEditing中将默认屏幕设置为低于..

-(void)textViewDidEndEditing:(UITextView *)textView
{
    [textView resignFirstResponder];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    self.view.frame = CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}

<强>更新

根据您的要求,我们使用我们的视图设置框架,请参阅下面的代码

-(void)textViewDidBeginEditing:(UITextView *)textView
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.3];
         [yourTextView setFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.‌​frame.size.width,self.view.frame.size.height - 160)];
        [UIView commitAnimations];

    }

-(void)textViewDidEndEditing:(UITextView *)textView
    {
        [textView resignFirstResponder];
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [yourTextView setFrame:self.view];
        [UIView commitAnimations];
    }