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>
bb10
Tor Arne Vestbø 2015-01-19 17:08:46 +01:00 committed by Tor Arne Vestbø
parent 73ef1ec693
commit 04e4a09b85
3 changed files with 14 additions and 16 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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];