diff options
authorTor Arne Vestbø <>2015-01-15 15:37:58 +0100
committerTor Arne Vestbø <>2015-01-21 19:12:27 +0100
commit13c491e6c8e9be0ec77e11fba02824acf7bb4eac (patch)
parentbdab31166ca4b8abd4b78301f92862828a2b61e7 (diff)
iOS: Fall back to statusbar orientation for initial QScreen::orientation()
At startup, iOS will report UIDeviceOrientationUnknown for the device orientation, which toQtScreenOrientation() maps to portrait. We can be smarter than that, by falling back to the orientation of the statusbar, which in most cases match the physical orientation of the screen at startup, unless the Info.plist file has been modified to limit the possible orientations. See also: Change-Id: I5c78fbe5c670ed2909a51b478bd4814e2433554f Reviewed-by: Tor Arne Vestbø <>
1 files changed, 13 insertions, 3 deletions
diff --git a/src/plugins/platforms/ios/ b/src/plugins/platforms/ios/
index 43bfed5cbb..0713a95522 100644
--- a/src/plugins/platforms/ios/
+++ b/src/plugins/platforms/ios/
@@ -152,8 +152,7 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen)
// orientations alongside these two orientations.
- Qt::ScreenOrientation screenOrientation = toQtScreenOrientation(deviceOrientation);
- QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), screenOrientation);
+ QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), m_screen->orientation());
@@ -321,7 +320,18 @@ Qt::ScreenOrientation QIOSScreen::nativeOrientation() const
Qt::ScreenOrientation QIOSScreen::orientation() const
- return toQtScreenOrientation([UIDevice currentDevice].orientation);
+ UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
+ // At startup, iOS will report an unknown orientation for the device, even
+ // if we've asked it to begin generating device orientation notifications.
+ // In this case we fall back to the status bar orientation, which reflects
+ // the orientation the application was started up in (which may not match
+ // the physical orientation of the device, but typically does unless the
+ // application has been locked to a subset of the available orientations).
+ if (deviceOrientation == UIDeviceOrientationUnknown)
+ deviceOrientation = UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation);
+ return toQtScreenOrientation(deviceOrientation);
void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)