2017-09-30 3 views
0

UICollection의 재정렬 기능을 구현하는 가장 일반적인 방법은 다음과 같은 일을 할 것입니다UICollectionView의 재 배열, 수평 변위

func handleLongPress(gesture: UILongPressGestureRecognizer){ 
    switch(gesture.state){ 
    case .began: 
     guard let selected = self.collectionView.indexPathForItem(at: gesture.location(in: self.collectionView)) else{ 
      break 
     } 
     self.collectionView.beginInteractiveMovementForItem(at: selected) 
    case .changed: 
     self.collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!)) 
    case .ended: 
     self.collectionView.endInteractiveMovement() 
    default: 
     self.collectionView.cancelInteractiveMovement() 
    } 
} 

및 구현

func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool { ... } 

func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { ... } 

이렇게하면 셀 위를 길게 누를 수 있습니다. 그러나 맨 왼쪽이나 먼 왼쪽을 오랫동안 길게 누르면 셀이 내 터치가있는 곳을 중심으로 이동합니다. 센터링 기능을 비활성화 할 수 있습니까?

답변

0
case .changed: 
     var location:CGPoint = gesture.location(in: gesture.view!) 
     location.x = self.collectionView.frame.midX 
     self.collectionView.updateInteractiveMovementTargetPosition(location) 

내가

을 필요로 결국 모든했다