Why are UIView frames made up of floats?

前端 未结 3 1441
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 05:13

Technically the x, y, width, and height represent a set of dimensions that relate to pixels. I can\'t have 200.23422 pixels so why do they use floats instead of ints?

3条回答
  •  自闭症患者
    2021-01-15 05:35

    Resolution independence.

    You want to keep your mathematical representation of your UI as accurate as practicable, only translating to pixel int values when you actually need to draw to the output device (and even then, not really). That's so that you can apply any number of transformations to your views and still get an accurate result.

    Moreover it is possible to render lines, for example, at half-pixel widths and even less with a visible result - the system uses intelligent antialiasing to display a fine line.

    It's the same principle as vector drawing has been using for decades (Adobe's PostScript, SVG etc). In fact Quartz is based on PDF, which is the modern version of PostScript. NeXT used Display PostScript in it's time, and then it was considered pretty revolutionary.

提交回复
热议问题