要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
ForceTouchable 可通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile 中
pod "ForceTouchable"
要在您所有的 UIViewControllers 上使用 ForceTouchable,只需实现 ForceTouchable 协议。如果您的 ForceTouchable 实现是 UIViewController,大多数方法已经实现,您需要实现的是 forceTouchPreviewForLocation(CGPoint)
并在 viewDidAppear
方法上调用 setupForceTouch()
// MARK: ForceTouchable
extension ViewController: ForceTouchable {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
setupForceTouch()
}
func forceTouchPreviewForLocation(location: CGPoint) -> ForceTouchPreview? {
guard let indexPath = tableView.indexPathForRowAtPoint(location),
cell = tableView.cellForRowAtIndexPath(indexPath) else { return nil }
// Create a detail view controller and set its properties.
guard let detailViewController = storyboard?.instantiateViewControllerWithIdentifier("DetailViewController") as? DetailViewController else { return nil }
let previewDetail = sampleData[indexPath.row]
detailViewController.detailItemTitle = previewDetail.title
return ForceTouchPreview(previewViewController: detailViewController, touchedView: cell)
}
}
Ivan Bruel,[email protected]
ForceTouchable 适用于 MIT 许可证。请查看 LICENSE 文件以了解更多信息。