我有一个带有 Tableview 的 viewController、多个 TableViewCell,并且在每个 TableViewCell 中都有一个带有多个 UICollectionViewItems 的 UICollectionView。每个collectionView项目都有一个标签和图像视图。我正在尝试让 3d 触摸工作,以便用户通过强制触摸 tableCell 不包含集合视图的区域来进行窥视和弹出,以预览并弹出到一个视图控制器中,然后能够执行以下操作与 collectionView 中的一张图像相同,但预览并弹出到不同的视图控制器中。我的第一个场景工作正常,当开始强制触摸和“偷看”时,tableCell 在屏幕上保持清晰。我坚持让它在集合视图中工作,无论我做什么,只有图像视图框架在第一个表格视图行上保持清晰,无论我实际按下哪一行。代码如下:
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
//get the tableviewCell
if let tableCellPath = tableView.indexPathForRow(at: location) {
print("tableCellPath=", tableCellPath)
if let tableCell = tableView.cellForRow(at: tableCellPath) as? VenueMainTableViewCell {
//user tapped on a beer in the collectionview
if let collectionView = tableCell.collectionView {
let collectionPoint = collectionView.convert(location, from: tableView)
if let cvPath = collectionView.indexPathForItem(at: collectionPoint) {
let collectionViewCell = collectionView.cellForItem(at: cvPath) as? VenueMainCollectionViewCell
let cvFrame = collectionViewCell?.itemLabelImageView.frame
let bc = storyboard?.instantiateViewController(withIdentifier: "itemDetail") as! ItemDetailViewController
let ven = UTcheckin.sharedInstance.Venues[collectionView.tag]
let selectedItem = ven.ItemsAtVenue[(collectionViewCell?.tag)!]
bc.item = selectedItem
previewingContext.sourceRect = cvFrame!
return bc
}
}
}
if let tablePath = tableView.indexPathForRow(at: location) {
//user tapping on a venue, this works
previewingContext.sourceRect = tableView.rectForRow(at: tablePath)
let vc = storyboard?.instantiateViewController(withIdentifier: "venueDetail") as! VenueDetailViewController
vc.venue = UTcheckin.sharedInstance.Venues[tablePath.row]
return vc
}
return nil
}
return nil
}
似乎我需要获取集合视图项图像视图的矩形,但由于它位于表格单元格中,因此如何访问它?预先感谢您的任何指点。
我认为这个问题的解决方案与UITableView
。您必须使用以下命令注册每个单元格以进行预览registerForPreviewingWithDelegate
方法。您应该将其注册在cellForRow
method.
这应该对你很有帮助。尤其The Solution
段落:
如何在 UITableViewCell 中查看和弹出特定视图 https://www.natashatherobot.com/peek-pop-view-inside-tableviewcell
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)