将CGRect标准化为0到1 [英] Normalising CGRect between 0 and 1

查看:69
本文介绍了将CGRect标准化为0到1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

规范化 CGRect 值以使它们介于0和1(单位坐标系)之间的最佳方法是什么?

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

推荐答案

这样做的一个非常简洁的方法是:

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

这篇关于将CGRect标准化为0到1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆