OGeek|极客世界-中国程序员成长平台

标题: ios - 长按并拖动时放大 UICollectionViewCell [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:44
标题: ios - 长按并拖动时放大 UICollectionViewCell

我想在长按和拖动时缩放 Collection View ,当用户结束拖动时,单元格应该是常规大小。

我正在使用以下步骤创建演示,这些步骤可以正常工作,但放大无法按预期工作。 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()
    }
}



Best Answer-推荐答案


在 Collection View 布局子类上试试这个:

- (UICollectionViewLayoutAttributes*) layoutAttributesForInteractivelyMovingItemAtIndexPathNSIndexPath *)indexPath withTargetPositionCGPoint)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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4