From 13c491e6c8e9be0ec77e11fba02824acf7bb4eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 15 Jan 2015 15:37:58 +0100 Subject: iOS: Fall back to statusbar orientation for initial QScreen::orientation() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://gist.github.com/torarnv/40c1931205e33d2b1ed3 Change-Id: I5c78fbe5c670ed2909a51b478bd4814e2433554f Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosscreen.mm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 43bfed5cbb..0713a95522 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -152,8 +152,7 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) // orientations alongside these two orientations. return; default: - 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) -- cgit v1.2.3