Skip to content

Instantly share code, notes, and snippets.

@sora0077
Created June 18, 2018 09:53
Show Gist options
  • Save sora0077/7e27931866b127d2dc0268482c90fcf2 to your computer and use it in GitHub Desktop.
Save sora0077/7e27931866b127d2dc0268482c90fcf2 to your computer and use it in GitHub Desktop.
// https://muukii.design/engineering/2017/10/17/create-cgaffinetransform-that-represents-cgrect-to-cgrect
extension CGAffineTransform {
init(from: CGRect, to: CGRect) {
self = CGAffineTransform(
a: to.width / from.width,
b: 0,
c: 0,
d: to.height / from.height,
tx: to.midX - from.midX,
ty: to.midY - from.midY
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment