1

我想縮放長按和拖拉時的collectionview,當用戶端拖動時,單元格應該以常規大小顯示。放大UICollectionViewCell長按並拖動時

我使用下面的步驟創建演示,但工作正常,但放大效果不如預期。 Collection View Example

這裏是動作代碼我使用:

func handleLongGesture(gesture: UILongPressGestureRecognizer) { 

    switch(gesture.state) { 

    case UIGestureRecognizerState.Began: 
     guard let selectedIndexPath = self.collectionView.indexPathForItemAtPoint(gesture.locationInView(self.collectionView)) else { 
      break 
     } 
     collectionView.beginInteractiveMovementForItemAtIndexPath(selectedIndexPath) 
    case UIGestureRecognizerState.Changed: 
     collectionView.updateInteractiveMovementTargetPosition(gesture.locationInView(gesture.view!)) 
    case UIGestureRecognizerState.Ended: 
     collectionView.endInteractiveMovement() 
    default: 
     collectionView.cancelInteractiveMovement() 
    } 
} 

回答

2

試試這個對集合視圖佈局子類:

- (UICollectionViewLayoutAttributes*) layoutAttributesForInteractivelyMovingItemAtIndexPath:(NSIndexPath *)indexPath withTargetPosition:(CGPoint)position 
{ 
    UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForInteractivelyMovingItemAtIndexPath:indexPath withTargetPosition:position]; 
    attributes.zIndex = NSIntegerMax; 
    attributes.transform3D = CATransform3DScale(attributes.transform3D, 1.2f, 1.2f, 1.0); 
    return attributes; 
}