2014-04-02 101 views
0

[textField becomeFirstResponder]被稱爲單元格被鍵盤覆蓋時,我想要當單元格位置位於鍵盤上方時[textField becomeFirstResponder]被調用。我怎樣才能做到這一點?UITableViewCell單元格是鍵盤覆蓋

與iPhone短信功能類似!

+0

可能重複[鍵盤出現時調整視圖(IOS)(HTTP:/ /stackoverflow.com/questions/16043371/resize-a-view-when-a-keyboard-appears-ios) – Paulw11

回答

1

您可以使用下面的代碼來顯示您的文本字段這改變的tableview的tableview的底部「Y」座標

 #pragma mark - textfield delegate 

     - (void) textFieldDidBeginEditing:(UITextField *)sender { 
        activeTextField = sender; 

        if ([sender isEqual:TextField1]) { 
         [self setViewMovedForViewIndex:1]; 
        } 
        else if ([sender isEqual:TextView2]) 
        { 
         [self setViewMovedForViewIndex:2]; 
        } 

     } 

     - (BOOL)textFieldShouldReturn:(UITextField *)textField 
     { 
       [textField resignFirstResponder]; 
       [self setViewMovedForViewIndex:0]; 
       return YES; 
     } 

    - (void)setViewMovedForViewIndex:(int)index { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.5]; // if you want to slide up the view 

     CGRect rect = self.table.frame; 

     switch (index) { 
      case 0: 
       rect.origin.y = 0; 
       break; 
      case 1: 
       rect.origin.y = 0; 
       break; 
      case 2: 
       rect.origin.y = -160; 
       break; 
      default: 
       break; 
     } 

     self.table.frame = rect; 

     [UIView commitAnimations]; 
    } 
0

好像您在尋找KeyboardAccessory視圖。你可以做到這一點。看看this tutorial。我會幫你的。並試着研究它。

蘋果已爲此a sample