1

我的观点是这样的:

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

}

这是我在提交新视图控制器之前强制触摸图像时在预览帧中得到的内容(因此外部模糊):

图像1

这就是我想要实现的,图像的角半径被保留(来自 App Store 的屏幕截图):

图2

通过阅读其他帖子,我认为问题在于我注册了整个 tableView 以进行预览,而不是其单元格。但是,我找不到适用于表视图单元格内的集合视图单元格的解决方案。

任何帮助表示赞赏。

4

2 回答 2

0

您是否尝试使用它的 cellAttributes 而不是转换框架?如果单元格的 contentView.layer 上有一个cornerRadius,请记住这一点。所以这样的事情对我们有用:

let cellAttributes = collectionView.layoutAttributesForItem(at: indexPath)

previewingContext.sourceRect = cellAttributes.frame
于 2018-04-19T09:54:19.757 回答
0

你能覆盖 UIImageView 并创建某种自定义绘图功能吗?

于 2017-02-22T18:40:27.797 回答