Ios 如何在UITextView中实现滚动功能?

Ios 如何在UITextView中实现滚动功能?,ios,uiscrollview,keyboard,scroll,uitextview,Ios,Uiscrollview,Keyboard,Scroll,Uitextview,我使用的是UITextView,如果文本在键盘下方展开,它就无法滚动,如下图所示。因此,如果文本与键盘对齐或在键盘下方,我需要某种向下滚动视图的滚动。我寻找过类似的例子/教程,但没有找到适合我的项目的好例子/教程 我将在下面的.h文件中发布我是如何实现UITextView*commentField的。从这里我该怎么办?如果你能成为一个具体的例子代码,将不胜感激/问候 ReportViewController.h文件: @interface ReportViewController : MLUI

我使用的是UITextView,如果文本在键盘下方展开,它就无法滚动,如下图所示。因此,如果文本与键盘对齐或在键盘下方,我需要某种向下滚动视图的滚动。我寻找过类似的例子/教程,但没有找到适合我的项目的好例子/教程

我将在下面的.h文件中发布我是如何实现UITextView*commentField的。从这里我该怎么办?如果你能成为一个具体的例子代码,将不胜感激/问候

ReportViewController.h文件:

@interface ReportViewController : MLUIViewController <MLReportErrorDelegate, UITextFieldDelegate, UIGestureRecognizerDelegate>
{

IBOutlet UITextView *commentField;
IBOutlet UITextField *emailField;

}

@property (nonatomic, retain) UITextView *commentField;

尝试此操作

键入时需要将文本视图设置为完全可见。我认为当文本进入键盘时,您无法动态滚动

您可以使用下面的代码来完成

//—-resize the scroll view (with keyboard)—-
CGRect viewFrame = [scrollView frame];
viewFrame.size.height -= keyboardRect.size.height;
scrollView.frame = viewFrame;

//—-scroll to the current text field—-
CGRect textFieldRect = [yourTextView frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];
//—-resize the scroll view (with keyboard)—-
CGRect viewFrame = [scrollView frame];
viewFrame.size.height -= keyboardRect.size.height;
scrollView.frame = viewFrame;

//—-scroll to the current text field—-
CGRect textFieldRect = [yourTextView frame];
[scrollView scrollRectToVisible:textFieldRect animated:YES];