我正在尝试在 UICollectionView 中实现新的拖放方法,但不知道如何从被拖动的单元格中删除背景。
这是问题的截图:
这是我正在尝试的代码:
func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
let parameters = UIDragPreviewParameters()
parameters.backgroundColor = .clear
return parameters
}
问题是,它并没有真正起作用。背景仍然可见。我正在考虑使用 visiblePath: UIBezierPath
,但我认为它不会很好地处理文本。
有没有办法完全删除这个背景?
最佳答案
我不确定是否有不使用 UIBezierPath
的方法。
这是我为类似的事情所做的一个例子:
final class CustomCell: UITableViewCell {
@IBOutlet weak var mySuperLabel: UILabel!
@IBOutlet weak var whiteSubview: UIView! // I have added a cornerRadius of 12.0 in the XIB
}
然后,委托(delegate)方法:
func tableView(_ tableView: UITableView, dragPreviewParametersForRowAt indexPath: IndexPath) -> UIDragPreviewParameters? {
let cell = tableView.cellForRow(at: indexPath) as! CustomCell
let previewParameters = UIDragPreviewParameters()
let path = UIBezierPath(roundedRect: cell.whiteSubview.frame, cornerRadius: 12.0)
previewParameters.visiblePath = path
previewParameters.backgroundColor = .clear
return previewParameters
}
结果:
关于ios - 如何更改正在使用 iOS11+ 拖放操作拖动的单元格的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52504120/