0

Hi I am facing a strange issue. I am adding a UIViewController to Window's RootViewController. I have set my ViewControllerXIB's autoresizing as MaskAll. When I run my project on iPad with iOS 7 in Landscape mode, I get screen size as (1024,768). But when I run on iPad with iOS 8, I get the screen size as (768,1024). I am not able to figure it out why this is happening. Due to this my ViewController's subviews are not loading with proper screen size since I am passing them the ViewController's screen size. Can anybody help me out on this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Shakti
  • 1,889
  • 4
  • 18
  • 29
  • See http://stackoverflow.com/questions/24150359/is-uiscreen-mainscreen-bounds-size-becoming-orientation-dependent-in-ios8 it's the same basic question. – rmaddy Oct 09 '14 at 03:51
  • There was a change in how the screen size is reported in Landscape in iOS 8 from all previous versions of iOS. I forget which WWDC video this is mentioned in so I can't point you to the docs. – Robotic Cat Oct 09 '14 at 03:51

1 Answers1

4

But when I run on iPad with iOS 8, I get the screen size as (768,1024).

It's because in iOS 7 and before, app rotation involves applying a rotation transform to the root view controller's view, while the window and screen remain pinned to the device. But in iOS 8, the entire app literally rotates. This is a major change and it can indeed break your existing code if you were expecting the rotation transform. On the other hand it's also much better - in iOS 8, rotation means that the screen, the window, the root view controller's view all simply change size (they swap their height and width) - and that means that if your app launches into landscape it has the correct dimensions right from the start.

If you need pure device coordinates in iOS 8 you can get them with the new UICoordinateSpace protocol (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICoordinateSpace_protocol/).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I should add that basically what you were doing before was wrong all along. You should not be looking at the screen size, but positioning your views with constraints. That way, your interface _adapts_ to whatever dimensions the superview may adopt. (Watch the WWDC 2014 video on making your app adaptive to learn more about this new philosophy...) – matt Oct 09 '14 at 04:32