Last active
August 24, 2017 11:39
-
-
Save saoudrizwan/8c378b1ca2e34b24fa9b966422aa27ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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