Last active
June 19, 2016 03:00
-
-
Save marmelroy/43bb1d4ac64560fd708de217025627a3 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
// Create interpolation object | |
let colorChange = Interpolate(from: UIColor.whiteColor(), to: UIColor.redColor(), apply: { [weak self] (color) in | |
self?.view.backgroundColor = color | |
}) | |
// For a gesture recognizer or delegate that reports every step of its progress (e.g. UIPanGestureRecognizer or a ScrollViewDidScroll) you can just apply the percentage directly to the Interpolate object | |
@IBAction func handlePan(recognizer: UIPanGestureRecognizer) { | |
let translation = recognizer.translationInView(self.view) | |
let translatedCenterY = view.center.y + translation.y | |
let progress = translatedCenterY / self.view.bounds.size.height | |
colorChange.progress = progress | |
} | |
// For other types of gesture recognizers that only report a beginning and an end (e.g. a UILongPressGestureRecognizer), you can animate directly to a target progress value with a given duration. | |
@IBAction func handleLongPress(recognizer: UILongPressGestureRecognizer) { | |
switch recognizer.state { | |
case .Began: | |
colorChange.animate(1.0, duration: 0.3) | |
case .Cancelled, .Ended, .Failed: | |
colorChange.animate(0.0, duration: 0.3) | |
default: break | |
} | |
} | |
// To remove | |
colorChange.invalidate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment