UITableView onTouch скрыть клавиатуру - PullRequest
2 голосов
/ 14 марта 2012

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

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

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

Ответы [ 2 ]

4 голосов
/ 14 марта 2012

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

//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 голосов
/ 14 марта 2012

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...