I am trying to implement Peek & Pop and so far, I've managed to successfully present my preview controller when a user does a 3d touch gesture. However, I would like to keep the preview controller in place even after the user releases his 3d touch gesture. I am pretty sure this automatically happens when the preview has associated actions, but in my case I don't have any.
Is there any standard or simple way to achieve this? I have tried to look around but so far I haven't gotten any success.
Additional question - It seems that my preview controller has some default transformation applied to it that makes it look smaller (or zoomed out). Is there any way to remove this and get the same look as if it was not presented through a peek?
In case it helps, here's my code so far (It's inside a UITableViewController
)
@objc internal func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = tableView.indexPathForRow(at: location),
let cell = tableView.cellForRow(at: indexPath),
let viewController = previewController(for: indexPath) else { return nil }
// Get frame for current cell
previewingContext.sourceRect = view.convert(cell.frame, from: tableView)
// Bind ViewModel
bindPreviewController!(viewController, indexPath)
// Set minimal size for Preview
viewController.preferredContentSize = viewController.view.systemLayoutSizeFitting(view.frame.size.withHeight(UILayoutFittingCompressedSize.height))
return viewController
}
/// To be overriden in subclasses
internal func previewController(for indexPath: IndexPath) -> UIViewController? {
return nil
}
@objc internal func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
// Not implemented just yet.
}