When the user is reordering their items and dragging on a cell, I want the cell to have a thin material as background. However, when the user isn’t dragging any cells, the background would be clear to allow the table view background to come through the cells.
I am unable to get this to work…
func tableView(_ tableView: UITableView, dragPreviewParametersForRowAt indexPath: IndexPath) -> UIDragPreviewParameters? {
// Create a copy of the cell for drag preview
guard let cell = tableView.cellForRow(at: indexPath) else { return nil }
// Create a visual effect view with blur effect
let blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThinMaterial))
blurEffectView.frame = cell.bounds
// Create a preview parameters object
let previewParameters = UIDragPreviewParameters()
let previewView = UIView(frame: cell.bounds)
previewView.addSubview(blurEffectView)
previewParameters.visiblePath = UIBezierPath(roundedRect: previewView.bounds, cornerRadius: 0)
previewParameters.backgroundColor = .clear
return previewParameters
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.backgroundColor = .clear
let item = fetchedResultsController.object(at: indexPath)
cell.contentConfiguration = UIHostingConfiguration {
ItemRow(item: item)
}
return cell
}