Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
I use code as below to get screen width, it is ok in Portrait mode,
the frame is (0, 0, 768, 1004),
but when I rotate it to Landscape mode,
the frame is (0, 0, 748, 1024), I need 1024, but it is not width, but height.

how can I get correct width inside view?
 
CGRect Documentation

In the default Quartz coordinate space, the origin is located in the lower-left corner of the rectangle and the rectangle extends towards the upper-right corner. If the context has a flipped-coordinate space—often the case on iOS—the origin is in the upper-left corner and the rectangle extends towards the lower-right corner.

It sounds like you should just flip the "height" and "width" coordinate in landscape orientation. The coordinate system appears to shift in landscape mode.
 
Last edited:
It does sort of make sense actually. That way in the two most common orientations (not counting upside down) the origin is always at the same physical corner of the device. It looks like you just have to take that into consideration when using the coordinate system.
 
It does sort of make sense actually. That way in the two most common orientations (not counting upside down) the origin is always at the same physical corner of the device. It looks like you just have to take that into consideration when using the coordinate system.
I am still in confused, I will read Coordinate system again.
Anyway, I got what I need follow your suggestion. Thanks a lot.
 
Thanks for your link, I had read similar document for iPhone, but I couldn't find why use height for width, is there any info about this topic?

Most likely the views coordinates have not changed but a transform has been applied so it displays rotated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.