【发布时间】:2017-07-12 22:54:58
【问题描述】:
我的视图结构如下:
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)
}
这是我的预览功能(灵感来自here):
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 的屏幕截图):
通过阅读other posts,我认为问题在于我注册了整个 tableView 以进行预览,而不是其单元格。但是,我找不到适用于表格视图单元格中的集合视图单元格的解决方案。
任何帮助表示赞赏。
【问题讨论】:
标签: ios swift uitableview 3dtouch peek-pop