0
나는 XX 이미지/셀로 UICollectionview
을 얻었으며 드래그 앤 드롭 할 때 스왑 장소로 만들고 싶습니다. 빌드 인 재정렬 기능을 사용하고 있지만 내 요구를 충족시키지 못합니다.UICollectionview 재정렬 이미지 셀
longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))
longPressGesture.minimumPressDuration = 0.2
longPressGesture.delaysTouchesBegan = true
cameraRollCollectionView.addGestureRecognizer(longPressGesture)
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case UIGestureRecognizerState.began:
guard let selectedIndexPath = cameraRollCollectionView.indexPathForItem(at: gesture.location(in: cameraRollCollectionView)) else {
break
}
cameraRollCollectionView.beginInteractiveMovementForItem(at: selectedIndexPath)
case UIGestureRecognizerState.changed:
cameraRollCollectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
case UIGestureRecognizerState.ended:
cameraRollCollectionView.endInteractiveMovement()
default:
cameraRollCollectionView.cancelInteractiveMovement()
}
}
나는 기본적으로 그냥 만, 첨부 된 이미지처럼 "이웃"이동 세포와 대상 세포 재정렬하지 스왑 애니메이션을 원하는 : 여기에 코드입니다.
내가이 코드를 "뒤에서"에서 일하고있다 : 당신이 셀에 긴 눌러를 인식 할 때
는func collectionView(_ collectionView: UICollectionView,
moveItemAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
let temp = selectedUIImages[sourceIndexPath.row]
selectedUIImages[sourceIndexPath.row] = selectedUIImages[destinationIndexPath.row]
selectedUIImages[destinationIndexPath.row] = temp
}
컬렉션보기가 실제로 가장 좋은 방법입니까? 나는 네가 원하는 방식으로 정확하게 동작하는 앱을 가지고 있기 때문에 (네모를 드래그하여 다른 스퀘어로 바꾸면), 콜렉션 뷰를 사용하지 않는다. 그것은 단지보기의 격자입니다. 나는 콜렉션 뷰가 제공하는 것을 필요로하지 않는다. – matt
라이브러리 사용에 관심이 있으시면 https://github.com/ra1028/RAReorderableLayout을 확인하십시오. –