2016-10-11 2 views
2

다른 크기의 셀이 있고 CollectionView 셀을 이동하려고하고 이동/선택된 셀 크기를 새 위치로 이동하려고합니다.UICollectionView 항목 이동 및 셀 크기 유지

나는 Github에서 project을 공개했습니다. 공동 작업자로 추가하고 싶다면 알려주세요.

나는 서브 UICollectionViewFlowLayout를 클래스라는하고 다음과 같은 구현 :

- (UICollectionViewLayoutInvalidationContext *)invalidationContextForInteractivelyMovingItems:(NSArray<NSIndexPath *> *)targetIndexPaths withTargetPosition:(CGPoint)targetPosition previousIndexPaths:(NSArray<NSIndexPath *> *)previousIndexPaths previousPosition:(CGPoint)previousPosition{ 

    UICollectionViewLayoutInvalidationContext *context = [super 
                  invalidationContextForInteractivelyMovingItems:targetIndexPaths 
                  withTargetPosition:targetPosition 
                  previousIndexPaths:previousIndexPaths 
                  previousPosition:previousPosition]; 

    [self.collectionView moveItemAtIndexPath:previousIndexPaths[0] toIndexPath:targetIndexPaths[0]]; 

    return context; 
} 

는 또한 UICollectionViewController에서이를 구현하려고 :

-(NSIndexPath *)collectionView:(UICollectionView *)collectionView targetIndexPathForMoveFromItemAtIndexPath:(NSIndexPath *)originalIndexPath toProposedIndexPath:(NSIndexPath *)proposedIndexPath{ 
    if (originalIndexPath.section == proposedIndexPath.section) { 
     return proposedIndexPath; 
    }else{ 
     return originalIndexPath; 
    } 
} 

당신이 크기를 유지하는 방법을 알고 계십니까?

+0

셀의 크기가 무작위입니까, 아니면 콘텐츠에 상대적으로 초기화되어 있습니까? –

+0

내용과 관련이 있습니다. 나는 다음으로부터 영감을 받았다. http://nshint.io/blog/2015/07/16/uicollectionviews-now-have-easy-reordering/ –

+0

좋아, 문제는 당신의 드롭 된 뷰가 이전과 같은 크기가 아니라는 것이다. 그것을 끈다 고요? –

답변

0

동일한 문제가 발생했습니다. 그 이유는 위임자의 moveItemAtIndexPath를 호출해야하기 때문입니다.

- (UICollectionViewLayoutInvalidationContext *)invalidationContextForInteractivelyMovingItems:(NSArray<NSIndexPath *> *)targetIndexPaths withTargetPosition:(CGPoint)targetPosition previousIndexPaths:(NSArray<NSIndexPath *> *)previousIndexPaths previousPosition:(CGPoint)previousPosition{ 

    UICollectionViewLayoutInvalidationContext *context = [super 
                  invalidationContextForInteractivelyMovingItems:targetIndexPaths 
                  withTargetPosition:targetPosition 
                  previousIndexPaths:previousIndexPaths 
                  previousPosition:previousPosition]; 

    [self.collectionView.dataSource collectionView:self.collectionView moveItemAtIndexPath:previousIndexPaths[0] toIndexPath:targetIndexPaths[0]]; 

    return context; 
}