我在我的集合视图单元格中添加了 3D Touch Peek/Pop 功能,效果很好,但是我注意到预览框架不尊重单元格的角半径。
这是我的预览功能:
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
let viewController = storyboard?.instantiateViewControllerWithIdentifier("scholarDetailViewController") as? ScholarDetailViewController
let cellPosition = self.scholarsCollectionView.convertPoint(location, fromView: self.view)
let cellIndex = self.scholarsCollectionView.indexPathForItemAtPoint(cellPosition)
guard let previewViewController = viewController, indexPath = cellIndex, cell = self.scholarsCollectionView.cellForItemAtIndexPath(indexPath) else {
return nil
}
let scholar = self.searchBarActive ? self.searchResults[indexPath.item] as! Scholar : self.currentScholars[indexPath.item]
previewViewController.setScholar(scholar.id)
previewViewController.delegate = self
previewViewController.preferredContentSize = CGSize.zero
previewingContext.sourceRect = self.view.convertRect(cell.frame, fromView: self.scholarsCollectionView)
return previewViewController
}
我已经尝试设置 previewingContext sourceView 的角半径并在单元格上使用 maskToBounds ,但到目前为止我尝试过的没有任何帮助。
这是单元格设置:
override func awakeFromNib() {
self.layer.cornerRadius = 7
}
有人有什么建议吗?