0

UICollectionViewUICollectionViewLayoutを実装し、カスタムフロー/ページング機能にはtargetContentOffsetForProposedContentOffsetを使用しています。各セルはほぼ画面の幅になり、次のセルはわずかに右側に表示されます。機能は素晴らしいですが、現在のセルがインデックス1である場合、インデックス0のセルを削除できるようにしたいと思います。現在、これを計算して実行できますが、インデックス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]、コレクションビューは、I「は次のcell..andにスクロールされますそれを止める方法がわからない。

私は削除後にself.collectionview.contentOffset = CGMakePoint(0,0)を試しましたが、移行はまだかなりバグがあります。どのようにこの問題にアプローチする上の任意のアイデアですか?

答えて

0

このように、試行錯誤の後、私は問題を解決することができました。それはちょっとハッキリかもしれないが、私はちょうど期間がないuiviewアニメーションでバッチをラップした。基本的には、削除アニメーションを無効にします。

[UIView animateWithDuration:0 animations:^{ 
    [self.collectionView performBatchUpdates:^{ 
     [scrollView setContentOffset:CGPointMake(0, 0) animated:NO]; 
     [self.data removeObjectAtIndex:0]; 
     NSIndexPath *indexPath =[NSIndexPath indexPathForRow:0 inSection:0]; 
     [self.collectionView deleteItemsAtIndexPaths:@[indexPath]]; 
     [self.collectionView.collectionViewLayout invalidateLayout]; 
    } completion:nil]; 
}]; 
関連する問題