为什么UIView框架由浮子组成? [英] Why are UIView frames made up of floats?

查看:82
本文介绍了为什么UIView框架由浮子组成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

技术上,x,y,width和height表示与像素相关的一组尺寸。我
不能有200.23422像素所以为什么他们使用浮点数而不是整数?

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?

推荐答案

原因浮点数是现代CPU和GPU优化为并行处理许多浮点数。这适用于iOS和Mac。

The reason for the floats are that modern CPUs and GPUs a are optimized to work with many floating point numbers in parallel. This is true for iOS as well as Mac.

使用Quartz,您不会处理单个像素,但您绘制的所有内容始终是抗锯齿的。如果你有一个坐标1.0,1.0,那么这实际上会为坐标原点的2x2像素增加颜色。

With Quartz you don't address individual pixels, but everything you draw is always antialiased. When you have a coordinate 1.0, 1.0 then this actually adds color to the 2x2 pixels at the coordinate origin.

这就是为什么你在整数绘制时可能会出现模糊线条的原因坐标。在非视网膜上你可以画出0.5的偏移量。从技术上讲,你需要偏移0.25才能在Retina显示屏上绘制精确的像素。虽然它并没有那么重要,因为你在那个像素大小上不再真正看到它。

This is why you might get blurry lines if you draw at integer coordinates. On non-retina you habe to draw offset by 0.5. Technically you would need to offset by 0.25 to draw exact pixels on Retina displays. Though there it does not really matter that much because you don't really see it any more at that pixel size.

长话短说:你没有真正解决像素问题,但Graphics引擎会为您浮点坐标和像素之间的映射。

Long story short: you don't address pixels direcrly, but the Graphics engine maps between floating point coordinates and pixels for you.

这篇关于为什么UIView框架由浮子组成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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