Created
June 12, 2019 23:45
-
-
Save wtsnz/f14575f4765568d2824ff350f521d1b3 to your computer and use it in GitHub Desktop.
Scale transform around anchor point
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 scaleTransform(for view: UIView, scaledBy scale: CGPoint, aroundAnchorPoint relativeAnchorPoint: CGPoint) -> CGAffineTransform { | |
let bounds = view.bounds | |
let anchorPoint = CGPoint(x: bounds.width * relativeAnchorPoint.x, y: bounds.height * relativeAnchorPoint.y) | |
return CGAffineTransform.identity | |
.translatedBy(x: anchorPoint.x, y: anchorPoint.y) | |
.scaledBy(x: scale.x, y: scale.y) | |
.translatedBy(x: -anchorPoint.x, y: -anchorPoint.y) | |
} |
@Wilsonilo That is a very good question... 4 years ago was a long time and I was deep in the context of graphics then so I can't be sure how I came up with it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!
Interesting using translated x 2 to regulate, is this your own inspiration?