Last active
March 17, 2016 01:29
-
-
Save andrewdolce/fdd6511b79ad5972f63a to your computer and use it in GitHub Desktop.
Social Tunes Sharer Code Sample: Ripple Animation (Part 1)
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
// From Andrew's code | |
func applyToView(view: UIView, fromView: UIView, duration: NSTimeInterval) { | |
let rect = view.convertRect(fromView.bounds, fromCoordinateSpace: fromView) | |
applyToView(view, fromRect: rect, duration: duration) | |
} | |
func applyToView(view: UIView, fromRect: CGRect, duration: NSTimeInterval) { | |
view.addSubview(tintView) | |
tintView.transform = CGAffineTransformIdentity | |
tintView.frame = fromRect | |
tintView.layer.cornerRadius = min(CGRectGetWidth(fromRect), CGRectGetHeight(fromRect)) / 2 | |
// Choose a scale that will make the layer big enough to fill the entire superlayer | |
let xScaleFactor = CGRectGetWidth(view.bounds) / CGRectGetWidth(fromRect) | |
let yScaleFactor = CGRectGetHeight(view.bounds) / CGRectGetHeight(fromRect) | |
let scaleFactor = max(xScaleFactor, yScaleFactor) * 2 | |
let transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor) | |
// Kick off the animation | |
UIView.animateWithDuration(duration, delay: 0, options: [.CurveLinear], animations: { | |
self.tintView.transform = transform | |
}, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment