0

나는 UICollectionViewLayout을 구현하는 가로 UICollectionView을 가지고 있으며 사용자 지정 플링/페이징 기능에 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], 컬렉션 뷰가 나는 '다음 cell..and에 스크롤 및 삭제시 어떻게 멈추게할지 모르겠다.

삭제 후 self.collectionview.contentOffset = CGMakePoint(0,0)을 시도했지만 전환이 여전히 눈에 띄게 버그가 있습니다. 이 문제에 접근하는 방법에 대한 아이디어가 있습니까?

답변

0

그래서 많은 시행 착오 끝에이 문제를 해결할 수있었습니다. 그것은 조금 hackish 수도 있지만 난 그냥 지속 시간이없는 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]; 
}]; 
관련 문제