-1

At the top of a function that renders the background, I have:

int height = [[UIScreen mainScreen] bounds].size.height;
int width = [[UIScreen mainScreen] bounds].size.width;

When I NSLog the height and width, for a retina device in landscape mode, I get a height of 1024 and a width of 768. The image displayed is a rotation of the portrait image; if I turn the device on the side the image neatly fills the whole screen but as-is the background displays a horizontally squeezed image.

Should I do anything different to be correctly obtaining height and width? I would expect for a device in landscape orientation the height would be 768 and the width would be 1024. If [UIScreen mainScreen] knows that I really want the height to be greater than the width (whether or not I actually do), how can I either query the actual dimensions, or query whether the device is in portrait mode or landscape?

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • 1
    The accepted answer in this thread should help you: http://stackoverflow.com/questions/7905432/how-to-get-orientation-dependent-height-and-width-of-the-screen – Alex Sep 27 '13 at 17:32
  • Please restate your response in a thread so I can accept it. – Christos Hayward Sep 27 '13 at 17:56

1 Answers1

1

You will want to take into account the current interface orientation and handle the result of [[UIScreen mainScreen] bounds] accordingly. There is a great, detailed explanation of how to do this in the accepted answer to of this thead:

How to get orientation-dependent height and width of the screen?

Community
  • 1
  • 1
Alex
  • 1,625
  • 12
  • 18