ORStudios ORStudios - 1 year ago 106
iOS Question

Normalising CGRect between 0 and 1

What is the best way to normalise

values so that they are between 0 and 1 (unit coordinate system)?

omz omz
Answer Source

A very concise way of doing this would be:

CGAffineTransform t = CGAffineTransformMakeScale(1.0 / parentRect.size.width, 1.0 / parentRect.size.height);
CGRect unitRect = CGRectApplyAffineTransform(rect, t);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download