[英]How to make an UITextView scrollable when the keyboard appears?
我想知道如何在编辑UITextView
时使其可滚动吗? 当用户想要对其进行编辑时,将显示键盘,但是UITextView
不再可滚动。 因此,键盘后面的所有文本都不可见。
您可以减小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];
}
只需在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];
}
UPDATE
根据您的要求,我们用视图设置框架,请参见下面的代码
-(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.