Skip to content

Instantly share code, notes, and snippets.

@marekkrzynowek
Created October 11, 2017 13:01
Show Gist options
  • Save marekkrzynowek/c2c57516d89da007d10578287422e1ed to your computer and use it in GitHub Desktop.
Save marekkrzynowek/c2c57516d89da007d10578287422e1ed to your computer and use it in GitHub Desktop.
func animateTo(frame: CGRect, withDuration duration: TimeInterval, completion: ((Bool) -> Void)? = nil) {
guard let _ = superview else {
return
}
let xScale = frame.size.width / self.frame.size.width
let yScale = frame.size.height / self.frame.size.height
let x = frame.origin.x + (self.frame.width * xScale)/2
let y = frame.origin.y + (self.frame.height * yScale)/2
UIView.animate(withDuration: duration, delay: 0, options: .curveLinear, animations: {
self.layer.position = CGPoint(x: x, y: y)
self.transform = self.transform.scaledBy(x: xScale, y: yScale)
}, completion: completion)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment