Skip to content

Instantly share code, notes, and snippets.

@jyliang
Last active August 29, 2015 13:57
Show Gist options
  • Save jyliang/9554634 to your computer and use it in GitHub Desktop.
Save jyliang/9554634 to your computer and use it in GitHub Desktop.
Transformation Normalize
- (CGFloat)getTransformScale {
CGAffineTransform transform = self.transform;
CGFloat scale = sqrt(transform.a*transform.a + transform.c*transform.c);
return scale;
}
- (CGFloat)getTransformAngle {
CGAffineTransform transform = self.transform;
CGFloat angle = atan2(transform.b, transform.a);
return angle;
}
- (void)normalizeTransform {
CGFloat angle = [self getTransformAngle];
CGFloat scale = [self getTransformScale];
CGPoint center = self.center;
self.transform = CGAffineTransformIdentity;
self.frame = [SCViewUtil multiplyRect:self.frame byScale:scale];
self.center = center;
self.transform = CGAffineTransformMakeRotation(angle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment