触摸并保持调整UICollectionViewCell的大小

时间:2017-05-18 22:27:00

标签: swift uicollectionview

我正在尝试实现与移动图标时iPhone跳板相同的效果。当图标处于“摆动”模式,并且您触摸并按住一个图标时,它将展开一点点。

我目前UILongPressGestureRecognizer处理调整大小的动画,如下所示:

func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {

    let p = gestureReconizer.location(in: collectionView)
    let indexPath = self.collectionView?.indexPathForItem(at: p)

    if indexPath != nil && indexPath?.row != collectionData.count {
        if gestureReconizer.state == UIGestureRecognizerState.began {

            let cell = collectionView?.cellForItem(at: indexPath!)

            UIView.animate(withDuration: 0.5, animations: {
                cell?.frame = CGRect(x: (cell?.frame.origin.x)!, y: (cell?.frame.origin.y)!, width: (cell?.frame.width)! + 5, height: (cell?.frame.height)! + 5)
            })
        }
        else if gestureReconizer.state == .ended {

            let cell = collectionView?.cellForItem(at: indexPath!)

            UIView.animate(withDuration: 0.5, animations: {
                cell?.frame = CGRect(x: (cell?.frame.origin.x)!, y: (cell?.frame.origin.y)!, width: (cell?.frame.width)! - 5, height: (cell?.frame.height)! - 5)
            })
        }
    }
}

这会调整单元格的大小,但一旦移动它就会恢复原来的大小。

0 个答案:

没有答案