0
我有一個水平UICollectionView
實施UICollectionViewLayout
並使用targetContentOffsetForProposedContentOffset
自定義的投擲/尋呼功能。每個單元格幾乎是屏幕的寬度,下一個單元格顯示在右側。該功能很好,但我希望能夠刪除位於索引0的單元格,當前單元格是索引1.我目前能夠計算並做到這一點,但是在刪除索引0單元格後,它會滑動到下一個單元格(舊索引2,新1(刪除0之後)),因爲當前的內容偏移。我不知道如何在保持當前佈局的同時刪除索引0。UICollectionview自定義流佈局刪除單元格
現在我委託我做:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
float cellWidth = self.collectionView.bounds.size.width - 20;
float currentPage = self.collectionView.contentOffset.x/cellWidth;
if (currentPage == 1) {
[self remove:0];
}
}
-(void)remove:(int)i {
[self.collectionView performBatchUpdates:^{
[self.data removeObjectAtIndex:0];
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:0 inSection:0];
[self.collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
}];
}
所以計算和刪除工作正常,但在正在刪除[0],集合視圖滾動到下一cell..and我我不知道如何阻止它。我試過self.collectionview.contentOffset = CGMakePoint(0,0)
刪除後,但過渡仍然明顯錯誤。關於如何解決這個問題的任何想法?