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?

4

2 に答える 2

0

私はこれを以下のように自分で解決することができました。これは、アプリが横向きモードでのみ実行するように設定されている、iOS 8 を実行している現在のすべての iPhone/iPad デバイスで機能します。最初に投稿したコードが機能しない理由がわかりません。

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;
}
于 2014-09-21T17:51:30.607 に答える