0

I have an app that runs in landscape orientation. I have used the code below to make it work on iOS 8. This code works perfectly on the simulator for ALL devices. However, when I run it on an iPhone 5 device the layout is wrong. Having read some other questions on here and other places I believed that the screen bounds had been swapped round on iOS 8 when running in landscape mode but it seems that this is not always the case.

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
    ScreenHeight = screenSize.width;
    ScreenWidth = screenSize.height;
}
else
{
    ScreenHeight = screenSize.height;
    ScreenWidth = screenSize.width;
}

Why is the simulator doing something completely different from the device? Does this only affect iPhone 5 or all iPhones/iPads? I don't have access to all devices running different iOS versions so was relying on the simulator to provide accurate results.

Is there a more reliable way of implementing this?

2 Answers2

0

I have managed to resolve this myself as below. This works for all current iPhone/iPad devices running iOS 8 where the app is set to run in landscape mode only. Not sure why the code I originally posted doesn't work.

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;

if (screenSize.width > screenSize.height)
{
    ScreenHeight = screenSize.width;
    ScreenWidth = screenSize.height;
}
else
{
    ScreenHeight = screenSize.height;
    ScreenWidth = screenSize.width;
}
0

This is an enhancement, not a defect. For more information, please refer to the following post: Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

Community
  • 1
  • 1