我想用UIView动画制作改变UITableViewCell高度的动画(以后用春天的动画)。改变UITableViewCell高度的自定义动画
所以我必须:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor greenColor];
}
UILabel *viewLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, [[UIScreen mainScreen] bounds].size.width, 40.0f)];
viewLabel.text = @"Test";
viewLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:viewLabel];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates];
[self animateCell:indexPath andTableView:tableView];
[tableView endUpdates];
}
- (void)animateCell:(NSIndexPath*)indexPath andTableView:(UITableView*)tableView
{
[UIView animateWithDuration:1.0f animations:^
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect rect = cell.frame;
rect.size.height = 90.0f;
cell.frame = rect;
NSLog(@"%f", cell.frame.size.height);
}];
}
但它不工作。但是,如果我真的加入:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath isEqual:[tableView indexPathForSelectedRow]])
{
return 90.0f;
}
return 40.0f;
}
我看到小区正在改变其高度和动画应用到在animateCell方法创建自定义单元格
当你调用endUpdates,UITableView的执行默认的动画。动画属性基于表视图的数据源值。 – vokilam
因此,我不需要调用beginUpdates和endUpdates并为自定义动画(将邻近单元格的位置更改为动画动画)进行处理? – Dimitrio
你的动画应该是什么? – vokilam