我想在长按和拖动时缩放collectionview,并且在用户端拖动时,单元格应该为常规大小。

我正在使用以下步骤创建演示,效果很好,但放大效果不如预期。
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()
    }
}

最佳答案

在集合视图布局子类上尝试以下操作:

- (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;
}

关于ios - 长按并拖动时放大UICollectionViewCell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41590815/

10-14 23:36