我已经用uicollectionview实现了3D Touch,效果很好。但是,当uisearchController处于活动状态时,3D Touch不起作用。uisearchController使用collectionView显示结果。以下帖子也出现了同样的问题: 3d Peek&Pop搜索结果
有人有同样的问题吗?谢谢
我想出了解决方案:
扩展MyViewController:UISearchControllerDelegate {
func didPresentSearchController(_ searchController: UISearchController) {
if let context = previewingContext {
unregisterForPreviewing(withContext: context)
previewingContext = searchController.registerForPreviewing(with: self, sourceView: self.myCollectionView)
}
}
func didDismissSearchController(_ searchController: UISearchController) {
if let context = previewingContext {
searchController.unregisterForPreviewing(withContext: context)
previewingContext = registerForPreviewing(with: self, sourceView: self.myCollectionView)
}
}
Run Code Online (Sandbox Code Playgroud)
}