Skip to content

Instantly share code, notes, and snippets.

@saoudrizwan
Last active August 24, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saoudrizwan/8c378b1ca2e34b24fa9b966422aa27ab to your computer and use it in GitHub Desktop.
Save saoudrizwan/8c378b1ca2e34b24fa9b966422aa27ab to your computer and use it in GitHub Desktop.
import UIKit
var feedbackGenerator : UISelectionFeedbackGenerator? = nil
@IBAction func gestureHandler(_ sender: UIPanGestureRecognizer) {
switch sender.state {
case .began:
// Instantiate a new generator
feedbackGenerator = UISelectionFeedbackGenerator()
// Prepare the generator when the gesture begins
feedbackGenerator?.prepare()
case .changed:
// Check to see if the selection has changed...
if myCustomHasSelectionChangedMethod(translationPoint: sender.translation(in: view)) {
// Trigger selection feedback
feedbackGenerator?.selectionChanged()
// Keep the generator in a prepared state
feedbackGenerator?.prepare()
}
case .cancelled, .ended, .failed:
// Release the current generator
feedbackGenerator = nil
default:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment