4

I make application for Deployment target >= 7.1. And i see the "bug"... Application run in only landscape mode!

Code:

CGSize frameSize = [[UIScreen mainScreen] bounds].size;

In iOS 7 (iPhone 4), returned CGSize (width=320, height=480), but must returned 480x320 (Because run application in landscape mode). In iOS 8 (iPhone 4S), returned CGSize (width=480, height=320) - correct result.

The impression that iOS 7 returned frame without check landscape/portrait mode, and return size for portrait mode.

Thank.

zaph
  • 111,848
  • 21
  • 189
  • 228
ZhukV
  • 2,892
  • 6
  • 25
  • 36

2 Answers2

6

The behavior changed in iOS 8.

Quoting UIScreen documentation

Prior to iOS 8, a screen’s bounds rectangle always reflected the screen dimensions relative to a portrait-up orientation. Rotating the device to a landscape or upside-down orientation did not change the bounds. In iOS 8 and later, a screen’s bounds property takes the interface orientation of the screen into account. This behavior means that the bounds for a device in a portrait orientation may not be the same as the bounds for the device in a landscape orientation. Apps that rely on the screen dimensions can use the object in the fixedCoordinateSpace property as a fixed point of reference for any calculations they must make.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
6

Yes there is change in API for iOS 8.

Yes, it's orientation-dependent in iOS8, not a bug. You could review session 214 from WWDC 2014 for more info: "View Controller Advancements in iOS 8"

Quote from the presentation:

UIScreen is now interface oriented:

[UIScreen bounds] now interface-oriented
[UIScreen applicationFrame] now interface-oriented
Status bar frame notifications are interface-oriented
Keyboard frame notifications are interface-oriented

Possible duplicate que: Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

To achieve your goal, check iOS version and run the code accordingly:

How can we programmatically detect which iOS version is device running on?

Hope this helps.

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • 2
    Shouldn't `-convertRect:fromWindow:nil` continue to do the correct thing? If so then there's no need for the author to write his own little custom conversion code with a version check. Just use the intended built-in method? – Tommy Dec 13 '14 at 14:56