我有一个集合视图,我正在寻找一个效果,当一个单元被点击时,它会增长占据整个屏幕.为了实现这一点,我基本上只是调用performBatchUpdates内部didSelectItemAtIndexPath,并且sizeForItemAtIndexPath知道为所选单元格返回更大的大小.这一切都很有效,细胞会根据需要增长和缩小.
问题出在细胞内部.集合视图单元由由约束管理的中等复杂视图层次结构组成.我希望细胞的子视图随着动画细胞的增长而缩小.不幸的是,我的子视图会立即捕捉到他们的新位置,因为单元格会逐渐变为新的大小.如何确保单元格内容与单元格大小相同?
以下是集合视图控制器中的两个相关方法:
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if ([collectionView.indexPathsForSelectedItems containsObject:indexPath])
return CGSizeMake(collectionView.bounds.size.width - 20, collectionView.bounds.size.height - (20 + [self.topLayoutGuide length]));
else
return CGSizeMake(260, 100);
}
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView performBatchUpdates:nil completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
Ant*_*ine 11
我有完全相同的问题.经过多次尝试,以下代码为我做了诀窍.在批量更新后直接调用layoutIfNeed,持续时间为3.0(+ - batchupdate持续时间)为约束设置动画.
[self performBatchUpdates:nil completion:nil];
// IndexPath of cell to be expanded
UICollectionViewCell *cell = [self cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:0.3 animations:^{
[cell.contentView layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2988 次 |
| 最近记录: |