2017-11-28 3 views
1

최근 컬렉션 뷰를 연구합니다. 자신의 인덱스 경로에서 일부 셀을 고쳐야합니다. 즉, 다른 사람들과 교환해서 드래그해서는 안됩니다. 드래그를 방지하기 위해 * - (BOOL) collectionView : (UICollectionView *) collectionView canMoveItemAtIndexPath : (NSIndexPath ) indexPath을 사용할 수 있습니다. 나는 그들이 다른 세포들과 교환되는 것을 막을 수 없다.UICollectionView, 하나의 셀이 이동하는 것을 방지하는 방법

누구나 같은 문제가 발생합니까?

감사

+0

우리는 당신을 돕기 위해 더 컨텍스트가 필요합니다. 셀에 관해 달성하려는 레이아웃을 보여주는 스키마 또는 XIB 파일을 제공 할 수 있습니까? 그들은 (움직이지 않는) 특정한 자세를 취하고 있습니까? – Balanced

답변

0

collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath

참조 애플의 문서 사용해보십시오 : 항목의 상호 작용 이동하는 동안 https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/1618052-collectionview

를 수집보기는 당신이 제공하려는 있는지 이 메소드를 호출 제안 된 경로보다 다른 인덱스 경로 이 방법을 사용하면 사용자가 에서 항목을 잘못된 위치에 놓지 않도록 할 수 있습니다. 예를 들어 사용자가 특정 섹션에서 항목을 삭제하지 못하게 할 수 있습니다.

그래서 당신은 마지막 셀과 셀을 재정렬 방지하기 위해 원하는 경우 예를 들어, 당신은 할 수 :

func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath { 
    if proposedIndexPath.row == data.count { 
     return IndexPath(row: proposedIndexPath.row - 1, section: proposedIndexPath.section) 
    } else { 
     return proposedIndexPath 
    } 
} 
관련 문제