【发布时间】:2023-03-16 16:51:01
【问题描述】:
如果用户触摸它,我会更改 UICollectionViewCell 的高度。为此,我使用performBatchUpdates: 更改基础数据并使用标准单元格动画。这完美地工作,并且使用标准的增长和收缩动画来动画变化。
此外,我使用reloadSection 更新该部分中单元格的所有子视图。这是我的代码:
[collectionView performBatchUpdates:^{
dataHelper.isCellExpanded = !dataHelper.isCellExpanded;
} completion:^(BOOL finished) {
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]];
}];
我需要为展开的单元格状态实现子视图的灵活重新排序。所以我不使用自动布局。我只更改子视图框架,并希望将框架更改与UICollectionViewCell 动画一起制作动画。
问题是单元格的contentView 内的子视图在没有动画的情况下更新,并且在单元格的高度变化动画完成后。但我想动画单元格子视图以及高度变化的动画。如何实现?
更新
我的UICollectionViewCell 中的自定义动画方法如下所示:
- (void)animate {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^
{
CGRect labelFrame = self.testLabel.frame;
labelFrame.origin.y += 70;
self.testLabel.frame = labelFrame;
}
completion:nil];
}
我在我的UICollectionViewCell 子类的initWithFrame: 中创建testLabel,如下所示:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
CGRect cellFrame = CGRectMake(0, 0, frame.size.width, frame.size.height);
// content
_testLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, frame.size.height - 20, frame.size.width - 20, 20)];
_testLabel.backgroundColor = [UIColor redColor];
_testLabel.textColor = [UIColor blackColor];
_testLabel.text = @"test";
[self.contentView addSubview:_testLabel];
....
【问题讨论】:
标签: ios objective-c animation uicollectionview uicollectionviewcell