iOS: Limit auto-rotation to device screen (excludes external screens)

An external screen should always stay in the native orientation of the
screen, and not be affected by rotations of the device. If the user
requires the external content to follow the device rotation, this
can be done explicitly by listening to orientation changes of the
main screen, or using QSensors.

Change-Id: I3a98655d11915f0db107930e7d97a24417656bc9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
bb10
Tor Arne Vestbø 2015-01-19 17:11:26 +01:00 committed by Tor Arne Vestbø
parent d824c7bcc5
commit 29f96fab24
2 changed files with 22 additions and 20 deletions

View File

@ -227,30 +227,32 @@ void QIOSScreen::updateProperties()
m_geometry = fromCGRect(m_uiScreen.bounds).toRect();
m_availableGeometry = fromCGRect(m_uiScreen.applicationFrame).toRect();
Qt::ScreenOrientation statusBarOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation));
if (m_uiScreen == [UIScreen mainScreen]) {
Qt::ScreenOrientation statusBarOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation));
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_8_0) {
// On iOS < 8.0 the UIScreen geometry is always in portait, and the system applies
// the screen rotation to the root view-controller's view instead of directly to the
// screen, like iOS 8 and above does.
m_geometry = mapBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry);
m_availableGeometry = transformBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry).mapRect(m_availableGeometry);
}
if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_8_0) {
// On iOS < 8.0 the UIScreen geometry is always in portait, and the system applies
// the screen rotation to the root view-controller's view instead of directly to the
// screen, like iOS 8 and above does.
m_geometry = mapBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry);
m_availableGeometry = transformBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry).mapRect(m_availableGeometry);
}
QIOSViewController *qtViewController = [m_uiWindow.rootViewController isKindOfClass:[QIOSViewController class]] ?
static_cast<QIOSViewController *>(m_uiWindow.rootViewController) : nil;
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.
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.
Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(qtViewController.lockedOrientation));
QTransform transform = transformBetween(lockedOrientation, statusBarOrientation, m_geometry).inverted();
Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(qtViewController.lockedOrientation));
QTransform transform = transformBetween(lockedOrientation, statusBarOrientation, m_geometry).inverted();
m_geometry = transform.mapRect(m_geometry);
m_availableGeometry = transform.mapRect(m_availableGeometry);
m_geometry = transform.mapRect(m_geometry);
m_availableGeometry = transform.mapRect(m_availableGeometry);
}
}
if (screen() && screen()->orientation() != orientation())

View File

@ -239,7 +239,7 @@
-(BOOL)shouldAutorotate
{
return !self.lockedOrientation;
return m_screen->uiScreen() == [UIScreen mainScreen] && !self.lockedOrientation;
}
#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_6_0)