简体   繁体   English

当我向上滑动UIView时调整UITableView的大小,就像显示键盘时发生的情况一样

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

I am sliding up a UIView which has a UIDatePicker as a subview. 我正在滑动一个UIView ,其中有一个UIDatePicker作为子视图。 This is added above my UITableView , but unfortunately some of the tableView rows are still under my UIView . 这是添加到我的UITableView之上的,但是不幸的是,一些tableView行仍然在我的UIView

UITableView is pushed up with keyboard: UITableView用键盘向上推:

在此处输入图片说明

UITableView is NOT pushed up with my view, covers up last few fields: UITableView没有被我的视图推高,涵盖了最后几个字段:

在此处输入图片说明

Is it possible to resize the UITableView dynamically when I slide up my view, just like when the keyboard is shown when in a tableView and all the rows are still able to be seen? 当我向上滑动视图时,是否可以动态调整UITableView大小,就像在tableView显示键盘并且仍然可以看到所有行时一样?

EDIT: 编辑:

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

Yes, it is possible. 对的,这是可能的。 You could just go ahead and change the size of the UITableView dynamically as part of the animation that slides up the view. 您可以继续进行操作,并作为向上滑动视图的动画的一部分来动态更改UITableView的大小。 If you want to do what the UITableView actually does in response to the keyboard, leave its size alone and instead change its content inset and scroll indicator insets. 如果要执行UITableView实际响应键盘的操作,请不要更改其大小,而是更改其内容插图和滚动指示器插图。 See my answer here and the examples linked to: 请在此处查看我的答案以及链接到的示例:

uitableview not resizing with keyboard uitableview不使用键盘调整大小

Ok, it was easier than I thought. 好吧,这比我想象的要容易。 In my case, when I touch a row, I want the picker to show and the tableView to change its height, so I use: 就我而言,当我触摸一行时,我希望选择器显示,并且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];

Then when I click the done button, and want to return the tableView back to the full height and hide my datePicker, I use: 然后,当我单击完成按钮,并想将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;
        }
    }];

}

Also, when adding the pickerView as a subview, make sure to add it to the window : 另外,在将pickerView添加为子视图时,请确保将其添加到window

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM