Created
October 11, 2017 13:01
-
-
Save marekkrzynowek/c2c57516d89da007d10578287422e1ed 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
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