我想要一个文本发送视图,例如apple的电子邮件应用程序中的send-email视图。 (默认的iPhone emailapp)。
我尝试了一个带有2个TextFields和1个TextView的UIScrollView,但它看起来不太好,当我在TextView中输入文本时,scrollview没有功能并且视图不滚动(当我在第三行时文本隐藏键入...
这是一张图片: http://s3.imgimg.de/uploads/Bildschirmfoto20110823um1156940f792556940f791456940f79png.png
应该如下所示: http://a5.mzstatic.com/us/r1000/032/Purple/ea/4f/03/mzl.bxracfen.320x480-75.jpg
如何重建?
答案 0 :(得分:1)
在UITextfield中开始编写文本时向下滚动,请使用:
[yourScrollView scrollRectToVisible:CGRectMake(yourTextfield.frame.origin.x,yourTextField.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
此外,当您编辑TextView时(即在textViewDidBeginEditing方法中),使其框架更小,以使其完全可见。然后,当你完成文本的编辑时(即在textViewDidEndEditing方法中),将框架设置为最初的框架。
编辑:
//add this in .h file
NSInteger originalHeight;
//in .m file
- (void) textViewDidBeginEditing:(UITextView *)textView
{
[yourScrollView scrollRectToVisible:CGRectMake(yourTextView.frame.origin.x,yourTextView.frame.origin.y,yourScrollView.frame.size.width,yourScrollView.frame.size.height) animated:YES];
//now set the frame
//you just need to change the height, rest can be kept whatever they are
//set the newHeight so as to make the textview visible
originalHeight = yourTextView.frame.size.height;
yourTextView.frame = CGRectMake(x,y,width,newHeight);
//rest of the code
}
现在编辑完成后,将高度设置为之前的状态。
- (void) textViewDidEndEditing:(UITextView *)textView
{
yourTextView.frame = CGRectMake(x,y,width,originalHeight);
}