Skip to content

A Force Touch protocol for easy Force Touch integration

License

Notifications You must be signed in to change notification settings

ivanbruel/ForceTouchable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ForceTouchable

Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

ForceTouchable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ForceTouchable"

Usage

To use ForceTouchable on your UIViewControllers all you have to do is implement the ForceTouchable protocol. Most methods are already implemented in case your ForceTouchable implementation is a UIViewController, all you need to implement is forceTouchPreviewForLocation(CGPoint) and call setupForceTouch() on your viewDidAppear method.

// 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)
  }

}

Author

Ivan Bruel, [email protected]

License

ForceTouchable is available under the MIT license. See the LICENSE file for more info.