While peek and popping in a tableView, how do I make my previewingContext.sourceRect
rounded?
At the moment:
Force Touch on TableView Cell
Set the previewing delegate as such:
previewingContext.sourecRect = tableView.rectForRow(at: indexPath)
I have already tried setting the cell's cell.layer.cornerRadius
& cell.layer.maskToBounds = true
in cellForRowAtIndexPath
, However the previewing soruce rect is still a perfect rectangle.
Relevant code:
UIVIewControllerPreviewingDelegate
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
if tableView.isEditing == false {
guard let indexPath = tableView.indexPathForRow(at: location) else {
print("Nil Cell Found: \(location)")
return nil }
guard let detailVC = storyboard?.instantiateViewController(withIdentifier: "view") as? ViewController else { return nil }
previewingContext.sourceRect = tableView.rectForRow(at: indexPath)
return detailVC
} else {
return nil
}
}
TableView CellForRowAtIndexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CustomCell else { fatalError("No cell with identifier: cell") }
cell.titleLabel.text = "temp"
// cell.inputView?.layer.cornerRadius = 16.0
// cell.inputView?.layer.masksToBounds = true
// cell.contentView.layer.cornerRadius = 16.0
// cell.contentView.layer.masksToBounds = true
cell.layer.cornerRadius = 16.0
cell.layer.borderWidth = 2
cell.layer.borderColor = UIColor.orange.cgColor
cell.layer.masksToBounds = true
return cell
}
}
Currently when just force touching on a tableview cell the blue box in the image below is selected and is the sourcerect, however I want the orange rounded rect (of one cell) to be the source rect.
Do you want your
Peek
to be circle thenPop
as a normalViewController
? Because sourceRect is the source of your Preview (in this case your cell) and not your actual Preview.Try this if you want your Peek to become a circle, and Pop normally:
On your
previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
add this before you returnAnd on your
previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController)
add this before you show