summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2015-01-19 17:08:46 +0100
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-01-23 19:47:57 +0100
commit04e4a09b8567776a67bcc95a40aa70cee4248868 (patch)
tree463b21e4fa9cfbf4a5177149292dd60a15faead4 /src/plugins/platforms/ios
parent73ef1ec693ad355d95cb6796e34d11e2ee5a1224 (diff)
iOS: Base [QIOSViewController shouldAutorotate] on the locked orientation
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ø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm9
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.h1
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.mm20
3 files changed, 14 insertions, 16 deletions
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<QIOSViewController *>(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<QIOSViewController *>(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];