iOS功能说"CGRectMinY"应该是左下角

tra*_*uan 9 ios cgrect

根据Apple文档,

CGRectMinY(CGRect)rect返回指定矩形右上角的y坐标

它不应该是矩形的左下角吗?因为我认为Y轴是向下的.

Poc*_*chi 16

如果这是用于iOS我认为你的功能是错误的.

http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html

CGRectGetMinY

返回建立矩形底边的y坐标.

CGFloat CGRectGetMinY(CGRect rect);

参数

矩形

The rectangle to examine. 
Run Code Online (Sandbox Code Playgroud)

回报价值

指定矩形左下角的y坐标.可用性

Available in iOS 2.0 and later.
Run Code Online (Sandbox Code Playgroud)

相关示例代码

HeadsUpUI
oalTouch
PhotoScroller
QuartzDemo
SpeakHere
Run Code Online (Sandbox Code Playgroud)

在CGGeometry.h中声明

编辑:清除骚扰."CGRectGetMinY"是一个在CGRect上使用的函数,这意味着它将返回结果,就像它只考虑一个矩形一样.例如:

// With a self created element

CGRect rect = CGRectMake(0, 429, 100, 44);

NSLog(@"rect.origin.y: %f",rect.origin.y);
NSLog(@"rect.size.height: %f",rect.size.height);
NSLog(@"CGRectGetMinY(rect): %f",CGRectGetMinY(rect));
NSLog(@"CGRectGetMaxY(rect): %f",CGRectGetMaxY(rect));
Run Code Online (Sandbox Code Playgroud)

回报

2012-06-04 10:55:49.737 test[7613:707] rect.origin.y: 429.000000
2012-06-04 10:55:49.739 test[7613:707] rect.size.height: 44.000000
2012-06-04 10:55:49.741 test[7613:707] CGRectGetMinY(rect): 429.000000
2012-06-04 10:55:49.748 test[7613:707] CGRectGetMaxY(rect): 473.000000
Run Code Online (Sandbox Code Playgroud)

关键是要考虑这个,如果你要求最小值,你会得到一个比你要求最大值更低的值.即使您在不使用ios坐标系的情况下考虑这一点.

现在ios是倒置的,所以你必须考虑这个,前面的功能也会起作用,但从视觉上讲,结果是反转的,因为系统是倒置的.

// With an element on the screen

NSLog(@"gpsButton.frame.origin.y: %f",gpsButton.frame.origin.y);
NSLog(@"gpsButton.frame.size.height: %f",gpsButton.frame.size.height);
NSLog(@"CGRectGetMinY(gpsButton.frame): %f",CGRectGetMinY(gpsButton.frame));
NSLog(@"CGRectGetMaxY(gpsButton.frame): %f",CGRectGetMaxY(gpsButton.frame));
Run Code Online (Sandbox Code Playgroud)

回报

2012-06-04 10:55:49.725 test[7613:707] gpsButton.frame.origin.y: 429.000000
2012-06-04 10:55:49.727 test[7613:707] gpsButton.frame.size.height: 44.000000
2012-06-04 10:55:49.732 test[7613:707] CGRectGetMinY(gpsButton.frame): 429.000000
2012-06-04 10:55:49.735 test[7613:707] CGRectGetMaxY(gpsButton.frame): 473.000000
Run Code Online (Sandbox Code Playgroud)

对于看到这个的人来说,也没有错,min小于最大值.

因此,混淆在ios倒置系统中,因为您想要从倒置系统中检索视觉上较少的值.

这就是为什么它看起来很奇怪,CGGeometry中的描述是为"人类世界"而作出的.不适用于ios倒置系统.

  • 因为这是人类的便利方法,所以即使当ios坐标系向后时,人类通常也希望该点更接近地面.而且由于如果你想要顶部的那个你只需要frame/bounds.origin.y,而不是让你需要帧/ bounds.origin.y + frame/bounds.size.高度 (2认同)