2017-09-30 7 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) 

は私が

を必要とすることになったすべてでした
関連する問題