Why are UIView frames made up of floats?(为什么 UIView 框架是由浮动组成的?)
问题描述
从技术上讲,x、y、宽度和高度表示一组与像素相关的维度.一世不能有 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.
长话短说:您不会直接处理像素,但图形引擎会为您在浮点坐标和像素之间映射.
Long story short: you don't address pixels direcrly, but the Graphics engine maps between floating point coordinates and pixels for you.
这篇关于为什么 UIView 框架是由浮动组成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 UIView 框架是由浮动组成的?
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01