强制触摸UITableViewCell内部的UICollectionView [英] Force touch on UICollectionView inside of UITableViewCell
问题描述
我有一个带有Tableview的viewController,多个TableViewCells,并且在每个TableViewCell中都有一个带有多个UICollectionViewItems的UICollectionView.每个collectionView项目都有一个标签和图像视图.我正在尝试使3D触摸起作用,以便用户通过强制触摸不包含集合视图的tableCell区域来窥视和弹出,以预览并弹出到一个视图控制器中,然后能够执行与collectionView中的图像之一相同,但预览并弹出到另一个视图控制器中.我的第一种情况工作正常,当开始强制触摸和窥视"时,tableCell在屏幕上保持清晰.我一直坚持让它在集合视图中正常工作,无论我做什么,无论我实际按下哪一行,在第一张tableview行上,图像视图框都保持清晰.下面的代码:
I have a viewController with a Tableview, multiple TableViewCells and in each TableViewCell, a UICollectionView with multiple UICollectionViewItems. Each collectionView item has a label and image view. I'm trying to get 3d touch to work so that the user and peek and pop by force touching on areas of the tableCell that don't contain the collection view, to preview and pop into one view controller and then be able to do the same thing with one of the images in the collectionView but preview and pop into a different view controller. I have the first scenario working fine, the tableCell remains sharp on the screen when starting to force touch and "peek". I'm stuck on getting this to work in the collection view, no matter what I do only an image view frame remains sharp on the first tableview row regardless of which row i'm actually pressing. Code below:
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
}
似乎我需要获取集合视图项图像视图的矩形,但是由于它位于表单元格中,因此如何访问它?在此先感谢您提供任何指导.
It seems like I need to get the rect of the collection view item image view but how can I access this since it is in the table cell? Thanks in advance for any pointers.
推荐答案
我认为解决方案与 UITableView
相同.您必须使用 registerForPreviewingWithDelegate
方法注册每个单元以进行预览.您应该在中注册 cellForRow
方法.
I think the solution for this is the same as for UITableView
. You have to register each cell for previewing using registerForPreviewingWithDelegate
method. You should register it in
cellForRow
method.
这对您应该非常有帮助.尤其是解决方案
段落:
This should be very helpful for you. Especially The Solution
Paragraph:
How to Peek & Pop A Specific View Inside a UITableViewCell
这篇关于强制触摸UITableViewCell内部的UICollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!