0

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

4

2 回答 2

4

你可以减少 sizeOf 你 textView on keyBoard 出现

-(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];
}
于 2012-12-04T11:42:48.003 回答
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];
    }
于 2012-12-04T11:08:59.073 回答