Last active
August 29, 2015 13:57
-
-
Save jyliang/9554634 to your computer and use it in GitHub Desktop.
Transformation Normalize
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
- (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