我确定有must这是一种简单的方法,但我已经花了很长时间在各种兔子洞里,到目前为止还没有成功。
我有一个支持拖放的集合视图。被拖动的单元格有一个UIImageView
in the contentView
,并且图像视图的背衬层应用了角半径。单元格中所有视图的背景颜色都是清晰的。
拖动时,单元格具有白色背景,显示在图像视图的角落周围:
有没有办法使整个可拖动视图四舍五入;或者将其背景设置为清除,以便看不到烦人的白色边框?
UPDATE
事实证明解决方案is简单得令人尴尬(假设UIBezierPaths
符合您对简单的定义):
您需要覆盖collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath)
的方法UICollectionViewDragDelegate
协议,并返回UIDragPreviewParameters
设置适当的 UIBezierPath:
func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
let previewParams = UIDragPreviewParameters()
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 140, height: 140), cornerRadius: 20)
previewParams.visiblePath = path
return previewParams
}
这是一个简单的实现,它对CGRect
从中导出贝塞尔路径 - 这适用于我的场景,因为所有单元格的大小相同。更复杂的集合视图需要一些自定义计算。