2011-08-23 12 views
1

我想通過蘋果的電子郵件應用程序發送類似於發送電子郵件視圖的文本發送視圖。 (默認iPhone emailapp)。如何重建EMail-App文本樣式?

我試着用2 TextFields和1 TextView的UIScrollView,但它看起來不好,scrollview沒有功能,並且當我在TextView中輸入文本時視圖不滾動(文本隱藏在第三行時I型...

這裏有一個畫面: http://s3.imgimg.de/uploads/Bildschirmfoto20110823um1156940f792556940f791456940f79png.png

它應該是這樣的:? http://a5.mzstatic.com/us/r1000/032/Purple/ea/4f/03/mzl.bxracfen.320x480-75.jpg

如何重建

回答

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); 
} 
+0

您能否爲此添加更多代碼?在哪裏添加您的第一個ScrollDown方法? – Kovu

+0

請參閱編輯答案 – mayuur