Skip to content

Instantly share code, notes, and snippets.

@andrewdolce
Last active March 17, 2016 01:29
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 andrewdolce/fdd6511b79ad5972f63a to your computer and use it in GitHub Desktop.
Save andrewdolce/fdd6511b79ad5972f63a to your computer and use it in GitHub Desktop.
Social Tunes Sharer Code Sample: Ripple Animation (Part 1)
// 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