【发布时间】:2012-12-04 11:05:36
【问题描述】:
我想知道如何在编辑UITextView 时使其可滚动?当用户想要编辑它时,键盘会显示,但UITextView 不再可滚动。所以键盘后面的所有文字都是不可见的。
【问题讨论】:
-
更改滚动视图的大小,使其不再位于键盘后面。
标签: iphone objective-c keyboard scroll uitextview
我想知道如何在编辑UITextView 时使其可滚动?当用户想要编辑它时,键盘会显示,但UITextView 不再可滚动。所以键盘后面的所有文字都是不可见的。
【问题讨论】:
标签: iphone objective-c keyboard scroll uitextview
你可以缩小你在键盘上出现的 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];
}
【讨论】:
当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];
}
【讨论】: