我的观点是这样的:
UITableView
|
+-- MyTableViewCell
| |
| +-- UICollectionView
| |
| +-- MyCollectionViewCell
| |
| +-- UIImageView
UIImageView 被命名为'icon',它的层有一定的圆角半径。我已经为 Collection View 中的项目实现了 Peek 和 Pop 并且它可以工作,但我无法弄清楚如何在预览框架中包含图像的角半径。
这就是我注册 tableView 以进行预览的方式:
if #available(iOS 9.0, *), traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: tableView)
}
这是我的预览功能(灵感来自这里):
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = tableView.indexPathForRow(at: location) else { return nil }
guard let cell = tableView.cellForRow(at: indexPath) as? MyTableViewCell else { return nil }
guard let collectionIndex = cell.collectionView.indexPathForItem(at: self.view.convert(location, to: cell.collectionView)) else { return nil }
guard let collectionViewCell = cell.collectionView.cellForItem(at: collectionIndex) as? MyCollectionViewCell else { return nil }
let iconRect = tableView.convert(collectionViewCell.icon.frame, from: collectionViewCell.icon.superview!)
previewingContext.sourceRect = iconRect
return someViewController
}
这是我在提交新视图控制器之前强制触摸图像时在预览帧中得到的内容(因此外部模糊):
这就是我想要实现的,图像的角半径被保留(来自 App Store 的屏幕截图):
通过阅读其他帖子,我认为问题在于我注册了整个 tableView 以进行预览,而不是其单元格。但是,我找不到适用于表视图单元格内的集合视图单元格的解决方案。
任何帮助表示赞赏。