From 04e4a09b8567776a67bcc95a40aa70cee4248868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 19 Jan 2015 17:08:46 +0100 Subject: iOS: Base [QIOSViewController shouldAutorotate] on the locked orientation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of keeping a separate property for the auto-rotation. Allows us to override shouldAutorotate later on to make the decision even more fine grained. Change-Id: I9a3cd6c1316f2a5485a94ef8d9b633df87f46f5f Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosscreen.mm | 9 ++++----- src/plugins/platforms/ios/qiosviewcontroller.h | 1 - src/plugins/platforms/ios/qiosviewcontroller.mm | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 9087cc0ec5..2389796e58 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -243,16 +243,15 @@ void QIOSScreen::updateProperties() m_availableGeometry = transformBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry).mapRect(m_availableGeometry); } - if (![m_uiWindow.rootViewController shouldAutorotate]) { + QIOSViewController *qtViewController = [m_uiWindow.rootViewController isKindOfClass:[QIOSViewController class]] ? + static_cast(m_uiWindow.rootViewController) : nil; + + if (qtViewController.lockedOrientation) { // Setting the statusbar orientation (content orientation) on will affect the screen geometry, // which is not what we want. We want to reflect the screen geometry based on the locked orientation, // and adjust the available geometry based on the repositioned status bar for the current status // bar orientation. - // FIXME: Handle hybrid apps by eg. observing changes to the shouldAutorotate property - Q_ASSERT([m_uiWindow.rootViewController isKindOfClass:[QIOSViewController class]]); - QIOSViewController *qtViewController = static_cast(m_uiWindow.rootViewController); - Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(qtViewController.lockedOrientation)); QTransform transform = transformBetween(lockedOrientation, statusBarOrientation, m_geometry).inverted(); diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index df7ce0ff4a..9df983a665 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -43,7 +43,6 @@ class QIOSScreen; @property (nonatomic, assign) UIInterfaceOrientation lockedOrientation; // UIViewController -@property (nonatomic, assign) BOOL shouldAutorotate; @property (nonatomic, assign) BOOL prefersStatusBarHidden; @property (nonatomic, assign) UIStatusBarAnimation preferredStatusBarUpdateAnimation; diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index fb60a759bd..ea81033e43 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -159,8 +159,8 @@ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; #endif + self.lockedOrientation = UIInterfaceOrientationUnknown; self.changingOrientation = NO; - self.shouldAutorotate = [super shouldAutorotate]; // Status bar may be initially hidden at startup through Info.plist self.prefersStatusBarHidden = infoPlistValue(@"UIStatusBarHidden", false); @@ -201,6 +201,11 @@ // ------------------------------------------------------------------------- +-(BOOL)shouldAutorotate +{ + return !self.lockedOrientation; +} + #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_6_0) -(NSUInteger)supportedInterfaceOrientations { @@ -356,16 +361,12 @@ // so we keep the status bar in sync with content orientation. This will ensure // that the task bar (and associated gestures) are also rotated accordingly. - if (self.shouldAutorotate) { + if (!self.lockedOrientation) { // We are moving from Qt::PrimaryOrientation to an explicit orientation, // so we need to store the current statusbar orientation, as we need it // later when mapping screen coordinates for QScreen and for returning // to Qt::PrimaryOrientation. self.lockedOrientation = uiApplication.statusBarOrientation; - - // Calling setStatusBarOrientation only has an effect when auto-rotation is - // disabled, which makes sense when there's an explicit content orientation. - self.shouldAutorotate = NO; } [uiApplication setStatusBarOrientation: @@ -377,16 +378,15 @@ // that auto-rotation should be enabled. But we may be coming out of // a state of locked orientation, which needs some cleanup before we // can enable auto-rotation again. - if (!self.shouldAutorotate) { + if (self.lockedOrientation) { // First we need to restore the statusbar to what it was at the // time of locking the orientation, otherwise iOS will be very // confused when it starts doing auto-rotation again. - [uiApplication setStatusBarOrientation: - UIInterfaceOrientation(self.lockedOrientation) + [uiApplication setStatusBarOrientation:self.lockedOrientation animated:kAnimateContentOrientationChanges]; // Then we can re-enable auto-rotation - self.shouldAutorotate = YES; + self.lockedOrientation = UIInterfaceOrientationUnknown; // And finally let iOS rotate the root view to match the device orientation [UIViewController attemptRotationToDeviceOrientation]; -- cgit v1.2.3