【发布时间】:2013-01-13 19:53:08
【问题描述】:
我正在编写一个自定义的UICollectionViewFlowLayout,我注意到当我在集合视图上调用performBatchUpdates:completion: 时,所有部分都会调用initialLayoutAttributesForAppearingItemAtIndexPath: 和initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath:。结果是 所有 部分都应用了动画,而不是 只是 新添加的部分。
[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: 的调用以代替简单的更新,但无论如何,已经存在的部分(所有部分)都是动画的。我想出了一个检查解决方案,以确保我正在更改 only 最后一部分的布局属性,但感觉很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);
}
这是只为某些部分设置动画的正确方法吗?
【问题讨论】:
标签: objective-c ios6 uikit uicollectionview uicollectionviewlayout