1

我正在向上滑动UIViewaUIDatePicker作为子视图。这是在我的上方添加的UITableView,但不幸的是一些 tableView 行仍在我的UIView.

UITableView 用键盘向上推:

在此处输入图像描述

UITableView 没有被我的观点推高,涵盖了最后几个领域:

在此处输入图像描述

当我向上滑动视图时是否可以动态调整大小UITableView,就像在 a 中显示键盘tableView并且仍然可以看到所有行一样?

编辑:

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

4

2 回答 2

0

对的,这是可能的。作为向上滑动视图的动画的一部分,您可以继续动态更改 UITableView 的大小。如果你想做 UITableView 响应键盘的实际操作,不要管它的大小,而是改变它的内容插入和滚动指示器插入。在此处查看我的答案以及链接到的示例:

uitableview 不使用键盘调整大小

于 2012-12-21T00:43:17.940 回答
0

好吧,这比我想象的要容易。就我而言,当我触摸一行时,我希望选择器显示并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];
于 2012-12-21T17:24:09.630 回答