0
我创建了一个音板,并且当您长时间按压拼贴块(CollectionView Cell)时,它会变成3D Touch弹出式文本的拼贴。3D Touch不在CollectionView中
我有一个ViewCollection,故事板ID为'tilePreview'。下面的代码,但3D触摸没有。
我该怎么做?有谁能够帮助我?
import UIKit
import AVFoundation
class CollectionViewController: UICollectionViewController, UIViewControllerPreviewingDelegate {
@IBOutlet var soundBoard: UICollectionView!
var list = [String]()
var buttonOn: Bool = true
override func viewDidLoad() {
super.viewDidLoad()
if traitCollection.forceTouchCapability == UIForceTouchCapability.available {
registerForPreviewing(with: self, sourceView: collectionView!)
}
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> MyCollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionViewCell
let tileText = list[indexPath.row]
cell.cellTitle.text = tileText
return cell
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
Speak(currentTitle: list[indexPath.row])
}
// MARK: - Preview tile
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = collectionView?.indexPathForItem(at: location) else { return nil }
guard let cell = collectionView?.cellForItem(at: indexPath) else { return nil }
guard let detailVC = storyboard?.instantiateViewController(withIdentifier: "tilePreview") as? DetailViewController else { return nil }
previewingContext.sourceRect = cell.frame
return detailVC
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
show(viewControllerToCommit, sender: self)
}
}
上UICollectionView [强制触摸的可能的复制在UITableViewCell里面](https://stackoverflow.com/questions/41498963/force-touch-on-uicollectionview-inside-of-uitablev iewcell) – sschale
您需要注册每个collectionView,而不是更大的对象。在'cellForItemAt'内部做到这一点,并看到链接的帖子。 – sschale
你为什么[回滚编辑nathan制作](https://stackoverflow.com/posts/45261272/revisions)?在我看来,它通过改进语法明显地阐明了你的文章。我没有看到他改变你问题意义的地方。你不喜欢什么?或者是一个意外? –