Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalising CGRect between 0 and 1

What is the best way to normalise CGRect values so that they are between 0 and 1 (unit coordinate system)?

like image 238
ORStudios Avatar asked Apr 16 '13 15:04

ORStudios


1 Answers

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);
like image 87
omz Avatar answered Sep 21 '22 23:09

omz