Search code examples
ioscgrect

iOS function says "CGRectMinY" which should be bottom left corner


According to the Apple documentation,

CGRectMinY(CGRect) rect returns the y coordinate of the top right corner of the specified rectangle

Shouldn't it be the bottom left corner of the rectangle? Because I think the Y-axis is downwards.


Solution

  • If this is for iOS I think your function is wrong.

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

    CGRectGetMinY

    Returns the y-coordinate that establishes the bottom edge of a rectangle.

    CGFloat CGRectGetMinY ( CGRect rect );

    Parameters

    rect

    The rectangle to examine. 
    

    Return Value

    The y-coordinate of the bottom-left corner of the specified rectangle. Availability

    Available in iOS 2.0 and later.
    

    Related Sample Code

    HeadsUpUI
    oalTouch
    PhotoScroller
    QuartzDemo
    SpeakHere
    

    Declared In CGGeometry.h

    Edit: To clear the confussion. The "CGRectGetMinY" is a function to be used on CGRect, this means that it will return the result as if it was only considering a rectangle. for example:

    // 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));
    

    returns

    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
    

    The key is to JUST consider this, if you ask for the min you will get a lower value than if you ask for the max. Even if you think about this without using the ios coordinate system.

    NOW the ios IS inverted, so you have to consider this, the previous function will work as well, but visually speaking the result is inverted because the system is inverted.

    // 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));
    

    returns

    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
    

    For a person who sees this, there is also nothing wrong, min is less than max.

    So the confusion is in the ios inverted system, since you want to retrieve a visually less value from an inverted system.

    This is why it seems weird, the description in CGGeometry is made for the "human world". Not for ios inverted system.