2012-11-21 18 views
0

我正在使用UITextView,如果文本在鍵盤下方展開,則無法滾動,如下圖所示。因此,如果文本與鍵盤一致或位於鍵盤下方,我需要某種滾動方式向下滾動視圖。我找過類似的例子/教程,但沒有找到任何適合我的項目的好東西。如何在UITextView中實現滾動功能?

我會發布我在我的.h文件中如何在下面實現了我的UITextView * commentField。我應該從這裏做什麼?如果你可以成爲一個具體的示例代碼,將不勝感激! /問候

http://tinypic.com/view.php?pic=kck6t&s=6

ReportViewController.h文件:

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

IBOutlet UITextView *commentField; 
IBOutlet UITextField *emailField; 

} 

@property (nonatomic, retain) UITextView *commentField; 

ReportViewController.m文件:

- (void) textViewShouldBeginEditing:(UITextView *)commentField 
{ 
??????????????????????? 
} 

回答

0

你需要充分設置的TextView到打字時可見。我認爲當文本在鍵盤下方時不能動態滾動。

您可以使用下面的代碼。

//—-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];