Tôi đang viết UICollectionViewFlowLayout
tùy chỉnh và tôi nhận thấy rằng initialLayoutAttributesForAppearingItemAtIndexPath:
và initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath:
sẽ được gọi cho tất cả các mục khi tôi gọi performBatchUpdates:completion:
trên chế độ xem bộ sưu tập. Kết quả là tất cả các phần có hoạt ảnh được áp dụng cho chúng thay vì chỉ phần mới được thêm vào.UICollectionView performBatchUpdates: animates tất cả các phần
[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];
}];
Những gì tôi đã cố gắng cho đến nay là loại bỏ các cuộc gọi đến performBatchUpdates:completion:
thay cho bản cập nhật đơn giản, nhưng các phần đã tồn tại (tất cả trong số họ) đều hoạt hình trong anyway. Tôi đã đưa ra một giải pháp kiểm tra để đảm bảo rằng tôi đang thay đổi thuộc tính bố cục của chỉ phần cuối cùng, nhưng nó cảm thấy bị hack.
if (decorationIndexPath.section == [(id<UICollectionViewDataSource>)self.collectionView.delegate numberOfSectionsInCollectionView:self.collectionView] - 1)
{
layoutAttributes.alpha = 0.0f;
layoutAttributes.transform3D = CATransform3DMakeTranslation(-CGRectGetWidth(layoutAttributes.frame), 0, 0);
}
Đây có phải là cách thích hợp để thực hiện hoạt ảnh chỉ một số phần không?