2012-12-29 72 views
0

我有一個UITextView可編輯時,出現選擇鍵盤。問題是,當文字太大時,他會躲在鍵盤後面。我怎麼解決這個問題?IPhone TextView隱藏鍵盤

+0

您應該在出現KeyBoard時向上滾動視圖。使用本教程實現它http://www.cocoawithlove.com/2008/10/sliding-uitextfields-around-to-avoid.html – Sumanth

+0

[如何使UITextField在鍵盤存在時向上移動](http ://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present) – paulmelnikow

回答

2

這段代碼移動視圖了

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    //change origin y 
[UIView beginAnimations:nil context:self.view]; 
      [UIView setAnimationDuration:0.25]; 
      [self.view setFrame:CGRectMake(0,-150,320,436)]; 
      [UIView commitAnimations]; 

} 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
    //reset origin y 
[UIView beginAnimations:nil context:self.view]; 
      [UIView setAnimationDuration:0.25]; 
      [self.view setFrame:CGRectMake(0,0,320,436)]; 
      [UIView commitAnimations]; 

} 

根據您的要求設置x和y值。

+0

真的很有幫助;)。 –

0

此問題已被多次詢問。在發佈問題前請做一些Google搜索。無論如何...

請參閱this question由別人提問,並已成爲社區wiki。在這個問題上發佈了31個答案。

此外,您還可以與this tutorial

0

變化基本視圖大小協商時編輯的UITextField,降低基本視圖淵源考原點Y編輯文本字段

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    //change origin y 
} 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
    //reset origin y 
} 
0

使用UITextfield的委託方法。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
      [UIView beginAnimations:nil context:self.view]; 
      [UIView setAnimationDuration:duration]; 
      //change origin y 
      [self.view setFrame:CGRectMake(X,newY,width,height)]; 
      [UIView commitAnimations]; 

} 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField 
{ 
      [UIView beginAnimations:nil context:self.view]; 
      [UIView setAnimationDuration:duration]; 
      //reset origin y 
      [self.view setFrame:CGRectMake(X,Y,width,height)]; 
      [UIView commitAnimations]; 
} 

不要忘記設置UITextFieldDelegate在您的「.H」文件和相應的文本的Fileds textfiled.delegate = self