ios - 长按并拖动时放大 UICollectionViewCell

标签 ios drag-and-drop uicollectionview swift3 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()
    }
}

最佳答案

在 Collection View 布局子类上尝试一下:

- (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/

相关文章:

ios - 如何在 viewWillTransitionToSize 之后获取 subview 的大小

ios - 通过iOS上的SIM卡以编程方式获取IMEI和序列号

ios - 如何为我的 CollectionView 单元格提供 onclick 功能?

ios - popViewController 在 iOS 中的 NSURLSessionDataTask block 中不起作用

delphi - 如何将文本字符串及其超链接从 HTML 页面拖到 TEdit

c# - 使用 SendMessage 拖放

Javascript:使用拖放在屏幕上重新排列 div

iphone - UICollectionViewCell 与每行顶部对齐

ios - 如何执行modalSegue?

ios - 如何使用其 Web 内容制作 UIWebView 的 subview ?