我正在编写一个自定义UICollectionViewFlowLayout
,我注意到了这一点initialLayoutAttributesForAppearingItemAtIndexPath:
,当我在集合视图上initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath:
调用时,所有部分都会调用它。performBatchUpdates:completion:
结果是所有部分都应用了动画,而不仅仅是新添加的部分。
[collectionView performBatchUpdates:^{
currentModelArrayIndex++;
[collectionView insertSections:[NSIndexSet indexSetWithIndex:currentModelArrayIndex]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:currentModelArrayIndex-1]];
} completion:^(BOOL finished) {
[collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:currentModelArrayIndex] atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
}];
到目前为止,我尝试的是删除调用来performBatchUpdates:completion:
代替简单的更新,但是无论如何,已经存在的部分(所有部分)都是动画的。我想出了一个检查解决方案,以确保我只更改了最后一部分的布局属性,但感觉很hacky。
if (decorationIndexPath.section == [(id<UICollectionViewDataSource>)self.collectionView.delegate numberOfSectionsInCollectionView:self.collectionView] - 1)
{
layoutAttributes.alpha = 0.0f;
layoutAttributes.transform3D = CATransform3DMakeTranslation(-CGRectGetWidth(layoutAttributes.frame), 0, 0);
}
这是只为某些部分设置动画的正确方法吗?