Normalising CGRect between 0 and 1

前端 未结 3 510
遥遥无期
遥遥无期 2021-01-04 19:18

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

3条回答
  •  死守一世寂寞
    2021-01-04 19:49

    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);
    

提交回复
热议问题