簡體   English   中英

當我向上滑動UIView時調整UITableView的大小,就像顯示鍵盤時發生的情況一樣

[英]Resize UITableView when I slide up a UIView, just like how it happens when the keyboard is shown

我正在滑動一個UIView ,其中有一個UIDatePicker作為子視圖。 這是添加到我的UITableView之上的,但是不幸的是,一些tableView行仍然在我的UIView

UITableView用鍵盤向上推:

在此處輸入圖片說明

UITableView沒有被我的視圖推高,涵蓋了最后幾個字段:

在此處輸入圖片說明

當我向上滑動視圖時,是否可以動態調整UITableView大小,就像在tableView顯示鍵盤並且仍然可以看到所有行時一樣?

編輯:

剛剛找到了一個很棒的Apple示例: http : //developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html

對的,這是可能的。 您可以繼續進行操作,並作為向上滑動視圖的動畫的一部分來動態更改UITableView的大小。 如果要執行UITableView實際響應鍵盤的操作,請不要更改其大小,而是更改其內容插圖和滾動指示器插圖。 請在此處查看我的答案以及鏈接到的示例:

uitableview不使用鍵盤調整大小

好吧,這比我想象的要容易。 就我而言,當我觸摸一行時,我希望選擇器顯示,並且tableView更改其高度,所以我使用:

[UIView animateWithDuration:0.4 delay:0.0 options: UIViewAnimationCurveEaseOut animations:^{

    self.pickerView.frame = CGRectMake(0, self.view.bounds.size.height-200, self.view.bounds.size.width, self.pickerView.frame.size.height);

    // shrink the table vertical size to make room for the date picker
    CGRect newFrame = self.tableView.frame;
    newFrame.size.height -= self.pickerView.frame.size.height;
    self.tableView.frame = newFrame;

} completion:nil];

然后,當我單擊完成按鈕,並想將tableView返回到全高並隱藏我的datePicker時,我使用:

- (void)doneWithPicker:(BOOL)remove {

    CGRect newFrame = self.tableView.frame;
    newFrame.size.height += self.pickerView.frame.size.height;
    self.tableView.frame = newFrame;

    [UIView animateWithDuration:0.4 delay:0.0 options: UIViewAnimationCurveEaseOut animations:^{
        self.pickerView.frame = CGRectMake(0, self.view.bounds.size.height+300, self.view.bounds.size.width, self.pickerView.frame.size.height);
    } completion:^(BOOL finished){
        if (remove) {
            [self.pickerView removeFromSuperview];
            self.pickerView = nil;
        }
    }];

}

另外,在將pickerView添加為子視圖時,請確保將其添加到window

[self.view.window addSubview:self.pickerView];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM