當你開始寫裏面的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);
}
您能否爲此添加更多代碼?在哪裏添加您的第一個ScrollDown方法? – Kovu
請參閱編輯答案 – mayuur