[英]How to make an UITextView scrollable when the keyboard appears?
I would like to know how I can make my UITextView
scrollable when it's being edited ? 我想知道如何在编辑
UITextView
时使其可滚动吗? When the user wants to edit it, the keyboard shows but then the UITextView
is no more scrollable. 当用户想要对其进行编辑时,将显示键盘,但是
UITextView
不再可滚动。 So all the text behind the keyboard is not visible. 因此,键盘后面的所有文本都不可见。
You can reduce sizeOf you textView on keyBoard appear 您可以减小sizeOf您的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];
}
just scroll the view when UITextView
begin edit like this.. 只需在
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];
}
and in endEditing just set Default screen like bellow.. 在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];
}
UPDATE UPDATE
Here with your requirement we set the frame with our view see bellow code 根据您的要求,我们用视图设置框架,请参见下面的代码
-(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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.