2015-04-28 58 views
2

正如你所看到的,我的UITableView的滾動是最大的下降,但我的表不完全可見。爲什麼?我用UITableViewControllerUISearchController不會將我的UITableView向上移動

enter image description here

+1

組這隻要鍵盤出現'tableView.contentInset = UIEdgeInsetsMake(10,0,200,0);和'後鍵盤消失設置'table.contentInset = UIEdgeInsetsMake(0,0,0,0);' –

+0

你知道嗎,如何獲得鍵盤的高度?因爲兩個方向的高度都不相同。沒有使用通知?目前可見的鍵盤有可能嗎? –

回答

0

使用通知可能是獲取鍵盤高度最簡單的方式爲我評論集contentInset屬性滾動鍵盤上方的實現代碼如下,一旦它隱藏設置爲零昆蟲,

- (void)viewWillAppear:(BOOL)animate { 
    [super viewWillAppear:animate]; 
    // Do any additional setup after loading the view. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
      selector:@selector(keyboardShown:) 
        name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
      selector:@selector(keyboardHidden:) 
        name:UIKeyboardWillHideNotification object:nil]; 
    } 

- (void)viewWillDisappear:(BOOL)animated 
    { 
     //remove notifications 
    } 

- (void)keyboardShown:(NSNotification*)aNotification 
    { 
    NSDictionary* info = [aNotification userInfo]; 
    CGRect keyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 

    float height = keyboardRect.size.height; 
    tableView.contentInset = UIEdgeInsetsMake(10, 0, height, 0); 
    } 


    - (void)keyboardHidden:(NSNotification*)aNotification 
    { 
     [UIView animateWithDuration:0.2 animations:^{ 
     table.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); 
     }]; 
    } 
1

我建議在用戶開始滾動時儘快隱藏鍵盤。 Apple在他們自己的應用中實現了這種行爲。要做到這一點,添加在你的表視圖控制器:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { 
    [self.searchBar resignFirstResponder]; 
} 

這需要填充與搜索欄中searchBar屬性。

4

很好的替代奧爾特溫的答案是使用的UIScrollViewkeyboardDismissMode屬性:

tableView.keyboardDismissMode = .OnDrag 
相關問題