I'm assuming fromRect.origin
is CGPointZero
.
You need a compound transform that moves the origin to the lower left, flips the Y axis, and applies the scaling you want.
You can make a compound transform using the functions that modify a transform, like this:
- (CGAffineTransform)transformFromValueToScreen {
CGRect fromRect = self.valueSpace;
CGRect viewRect = self.screenSpace;
CGSize scales = CGSizeMake(viewRect.size.width/fromRect.size.width,
viewRect.size.height/fromRect.size.height);
CGAffineTransform transform = CGAffineTransformIdentity;
// Move origin from upper left to lower left.
transform = CGAffineTransformTranslate(transform, 0, fromRect.size.height);
// Flip the sign of the Y axis.
transform = CGAffineTransformScale(transform, 1, -1);
// Apply value-to-screen scaling.
transform = CGAffineTransformScale(transform, scales.width, scales.height);
return transform;
}