ios - UIDatePickers 高度没有动画?

标签 ios objective-c uitableview animation autolayout

我在静态 UITableViewCell 中有一个 UIDatePicker,应用了自动布局(到 datePicker)。 datePicker 会隐藏,直到选择了一个按钮。选择按钮时,datePicker 变为可见,cells 高度变大。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 1)
    {
        if (self.datePickerView.hidden == YES) {
            return 252 - self.datePickerView.bounds.size.height;
        }
        else return 252;
    }
    tableView.estimatedRowHeight = 150;
    return UITableViewAutomaticDimension;
}

- (IBAction)datePicker:(id)sender
{
    if (self.datePickerView.hidden == YES)
    {
        [self.datePickerView setHidden:NO];

        CGFloat originalHeight = 162;
        [self.datePickerView setFrame:CGRectMake(self.datePickerView.frame.origin.x, self.datePickerView.frame.origin.y, self.datePickerView.frame.size.width, 0)];
        [UIDatePicker animateWithDuration:1.0 animations:^(){
            [self.datePickerView setFrame:CGRectMake(self.datePickerView.frame.origin.x, self.datePickerView.frame.origin.y, self.datePickerView.frame.size.width, originalHeight)];
        }];
    } else {

        [self.datePickerView setHidden:YES];
    }
    [self.tableView beginUpdates];
    [self.tableView endUpdates];
}

button 被选中时,cells 高度是动画的,但 datePicker 不是。它只是出现,并妨碍一切,直到 cell 完成动画。

如何让 datePicker 为其高度设置动画,使其与 cell 一起设置动画?

最佳答案

更新框架不适用于自动布局。您必须更新约束才能执行动画。

在您的情况下,您应该为您的 datePickerview 设置单独的单元格,并从您的表格 View 中插入/删除该单元格,以便隐藏和显示带动画的选择器 View 。

[编辑] 此处的示例代码:http://www.filedropper.com/tableviewsample

关于ios - UIDatePickers 高度没有动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29706969/

相关文章:

iphone - UINavigationController 中的 UIWebView 不滚动

objective-c - 如何将 swift NSLayoutConstraint activateConstraints 翻译成 objective-c ?

iphone - 为什么 UITableView 对其委托(delegate)和数据源进行如此多的调用?

ios - Quickblox 链接器错误 : operator delete(void*)", 引用自

swift - 从解析查询后设置跟随按钮标题

ios - 如何像应用商店一样显示多个表格 View Controller ?

iphone - 后退按钮关闭 ios 中的应用程序

ios - 以编程方式更改 UICollectionView 属性

ios - 无法从 WebKit 正确使用 https ://vintage. myetherwallet.com

ios - Apple 的 advertisingIdentifier 与 mac 地址?