xcode CGRectIntegral 有什么用呢?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9975219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CGRectIntegral what is the usage of it?
提问by aksani56
How does one use the CGRectIntegral function? I understand it's purpose.
如何使用 CGRectIntegral 函数?我明白它的目的。
The documentationisn't clear on it's exact use.
该文件是不是它的确切用途明确。
回答by Hector
CGRectIntegral to convert any decimal values to their integer equivalents
see image may be you can understand
CGRectIntegral 将任何十进制值转换为它们的等效整数,
请参阅图像,您可能会理解
How do I fix it?
我如何解决它?
frame = CGRectIntegral(frame);
-OR-
-或者-
myTextView.frame = CGRectIntegral(myTextView.frame);
? see this for more information of CGRectIntegral
? 有关 CGRectIntegral 的更多信息,请参阅此内容
回答by Vignesh
CGRectIntegral
Method is used to create integer rect . I mean to say suppose if you calculate frame in app you may get frames value in float.
CGRectIntegral
方法用于创建整数 rect 。我的意思是说假设如果您在应用程序中计算框架,您可能会获得浮点数的框架值。
Setting float value as frame to some UIElement like UILabel
would make the text looks blur. To avoid that, we use CGRectIntegral
.Please look at the example below,
将浮点值设置为某些 UIElement 之类的框架UILabel
会使文本看起来模糊。为了避免这种情况,我们使用 CGRectIntegral
.请看下面的例子,
NSLog(@"%@",NSStringFromCGRect( CGRectIntegral(CGRectMake(0, 15.6, 16.1, 20.2))));
This will print, {0,15},{17,21}.
这将打印 {0,15},{17,21}。
This explanation is found in the header file.
这个解释可以在头文件中找到。
/* Expand `rect' to the smallest rect containing it with integral origin and
size. */
回答by Mike Weller
One particular usage is to fix frames that do not align perfectly with on-screen pixels.
一种特殊用途是修复与屏幕像素不完全对齐的帧。
See this question: UITextField blurred text
看到这个问题:UITextField 模糊文本
If a label or textfield has a frame that isn't pixel-aligned when rendered to the screen, the text will appear blurred. This can happen if you calculate the frame using division (for example to center it in a parent view).
如果标签或文本字段的框架在呈现到屏幕时未按像素对齐,则文本将显得模糊。如果您使用除法计算框架(例如将其在父视图中居中),就会发生这种情况。
CGRectIntegral
will remove the fractional part of the frame, fixing this problem. Note however that with retina displays a .5 frame value is pixel aligned, but CGRectIntgral will still remove the fractional part.
CGRectIntegral
将删除框架的小数部分,解决这个问题。但是请注意,对于视网膜显示,0.5 帧值是像素对齐的,但 CGRectIntgral 仍将删除小数部分。