Tar_Tw45
Tar_Tw45

Reputation: 3222

Confusing with "CGRectMake" coordinate

From the following code

// yPos = 0, width = 100, height = 150
[imagesMutable enumerateObjectsUsingBlock: ^(UIScrollView verticalScroll, NSUInteger idx, BOOL *stop){
  [verticalScroll addSubView:[UIImageView setFrame:CGRectMake(0, yPos, width, height)]]
  // some code
  yPos += (height + 15)
}];

Let's say, if imagesMutable got 3 objects. And as I read from somewhere that CGRectMake is using cartesian coordinate (x = 0, y = 0 will be bottom left). So, it should be

[verticalScroll addSubView:[UIImageView setFrame:CGRectMake(0, 0, 100, 150)]]
[verticalScroll addSubView:[UIImageView setFrame:CGRectMake(0, 165, 100, 150)]]
[verticalScroll addSubView:[UIImageView setFrame:CGRectMake(0, 330, 100, 150)]]

This should mean that

First CGRectMake should has bottom left at (0, 0) and top right at (100, 150)
Second CGRectMake should has bottom left at (0, 165) and top right at (100, 315) 
Third CGRectMake should has bottom left at (0, 330) and top right at (100, 480)

Then, the order of images from top to bottom should be 3 -> 2 -> 1 comparing to the imagesMutable's objects ordering (1 -> 2 -> 3)

But why, it appearing in order of 1 -> 2 -> 3 as same as imagesMutable's objects ordering when I launch the app? Am I missing something?

Upvotes: 1

Views: 9849

Answers (1)

Manlio
Manlio

Reputation: 10865

(0,0) is not bottom-left but top-left.

The view has inverted y coordinates, so that y increases as you move down the screen.

enter image description here

Upvotes: 33

Related Questions