Created
October 11, 2017 13:05
-
-
Save marekkrzynowek/b5bc2ae2188e5fe0e6a71186845b0eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| extension UIView { | |
| 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) * self.layer.anchorPoint.x | |
| let y = frame.origin.y + (self.frame.height * yScale) * self.layer.anchorPoint.y | |
| 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