UICollectionViewCell使用约束进行动画处理

时间:2015-09-01 11:06:29

标签: ios objective-c uicollectionview uicollectionviewcell

我试图在按下时垂直展开细胞。在细胞扩张的那一刻,它只是与其周围的其他细胞重叠。

有关如何使用约束让其他单元格调整此大小变化的任何建议吗?

以下是我正在使用的代码:

UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

  [UIView transitionWithView:collectionView
                    duration:.5
                     options:UIViewAnimationCurveEaseIn
                  animations:^{

                    cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, 500, cell.frame.size.height);

                    [cell setBackgroundColor:[UIColor greenColor]];
                  } completion:^(BOOL finished) {


                  }];

编辑:这不是重复,因为上一个问题无法解决我的问题。

1 个答案:

答案 0 :(得分:1)

为集合视图单元设置动画的最简单方法是重新加载单元格并从sizeForItemAtIndexPath:方法返回新大小。在您设置数据源控制器之后,只需使用

重新加载布局
[collectionView setCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init] animated:YES];

这给出了一个非常流畅的动画。

相关问题