2012-03-14 2 views
2

У меня есть UITableView, где я разместил UIButton (как подвид ячейки). Также ниже таблицы, у меня есть UITextField. При касании текстового поля клавиатура появляется как обычно. Я хочу убрать клавиатуру при касании стола.UITableView onTouch скрыть клавиатуру

Один из вариантов, который я рассматривал, устанавливал UITapGestureRecognizer для UITableView. Но я поднял эту идею, поскольку у меня есть кнопка на tableCell, которая затем перестает отвечать.

Кроме того, я не хочу кнопку «Готово» или «возврат» на клавиатуре. Я хочу сказать, что я не хочу, чтобы клавиатура исчезала с клавиатуры, но касалась стола, заботясь о кнопке, которую она имеет.

+0

проверьте это. http://stackoverflow.com/a/6370673/641062 – Vignesh

ответ

4

Может быть, вы можете попробовать это.

//NSnotification when keyboard is shown 
- (void)keyboardWasShown:(NSNotification *)notification 
{  
    // Get the size of the keyboard. 
    if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){ 

     if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation){ 
      keyboardSize=CGSizeMake(320.000000, 216.000000); 
     } 
    else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation) 
     { 
      keyboardSize=CGSizeMake(162.000000, 480.000000); 
     } 
    } 
    else if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){ 
     if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation) 
      keyboardSize=CGSizeMake(768.000000, 264.000000);   

     else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation) 
     { 
      keyboardSize=CGSizeMake(352.000000,1024.000000); 

     } 
    } 

    // Adjust the bottom content inset of your scroll view by the keyboard height. 
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0); 
    scrvwLogig.contentInset = contentInsets; 
    scrvwLogig.scrollIndicatorInsets = contentInsets; 

    // Scroll the target text field into view. 
    CGRect aRect = self.view.frame; 
    aRect.size.height -= keyboardSize.height; 
    if (!CGRectContainsPoint(aRect, txtpassword.frame.origin)) { 

     CGPoint scrollPoint=CGPointZero; 
     //check flag for iPhone orientation 
     if(flgLandScape)   
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-70); 
     //check flag for iPhone/iPad orientation 
     else if(flgPort || flgPortiPad) 
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y - (keyboardSize.height-50));   
     //check flag for ipad orientation 
     else if(flgLandScapeiPad)   
      scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-130); 

     [scrvwLogig setContentOffset:scrollPoint animated:YES]; 
    } 
} 


//when keyboard is hide 

- (void) keyboardWillHide:(NSNotification *)notification { 

    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    scrvwLogig.contentInset = contentInsets; 
    scrvwLogig.scrollIndicatorInsets = contentInsets; 
} 
+0

Аналогичный код по крайней мере работает со мной! :) –

+0

+1 :-) Для приятного объяснения с кодом. –

0

Вы также можете использовать UIView (ИЛИ UIButton). Перед тем, как появится клавиатура, добавьте прозрачный UIView (320x480) и на сенсорном событии этого вида, вы можете скрыть клавиатуру и удалить представление.

+0

Тогда как бы прокрутить таблицу ??? – Nitish

+0

@Nitish: hmm true ... так что вы хотите скрыть клавиатуру при прокрутке или касании? – Maulik

+0

@Nitish: Другой способ, которым вы можете попробовать, - это когда свитки таблицы скрывают клавиатуру. – Maulik