Search code examples
iosipadios7ios8xib

Getting different Frame for RootViewControllers for iOS 7 and iOS 8


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?


Solution

  • 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/).