iOS: Calculate screen (available) geometry using [UIView convertRect]
Instead of custom logic to detect portrait/landscape and the height of the status bar. The latter would fail when the statusbar/orientation was set explicitly through [UIApplication setStatusBarOrientation], as the statusbar would not follow the normal behavior of covering the top part of the screen. The new code also handles upside-down portrait mode, as well as iOS8's behavior of reporting screen bounds and application frame in interface orientation instead of device orientation. Change-Id: I54e3b99246a32e17aaba13960f456fa823768fd8 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
This commit is contained in:
parent
d2c925b977
commit
4f0cd0693a
@ -241,17 +241,10 @@ void QIOSScreen::updateProperties()
|
||||
QRect previousGeometry = m_geometry;
|
||||
QRect previousAvailableGeometry = m_availableGeometry;
|
||||
|
||||
bool inPortrait = UIInterfaceOrientationIsPortrait(m_uiWindow.rootViewController.interfaceOrientation);
|
||||
m_geometry = inPortrait ? fromCGRect(m_uiScreen.bounds).toRect()
|
||||
: QRect(m_uiScreen.bounds.origin.x, m_uiScreen.bounds.origin.y,
|
||||
m_uiScreen.bounds.size.height, m_uiScreen.bounds.size.width);
|
||||
UIView *rootView = m_uiWindow.rootViewController.view;
|
||||
|
||||
m_availableGeometry = m_geometry;
|
||||
|
||||
CGSize applicationFrameSize = m_uiScreen.applicationFrame.size;
|
||||
int statusBarHeight = m_geometry.height() - (inPortrait ? applicationFrameSize.height : applicationFrameSize.width);
|
||||
|
||||
m_availableGeometry.adjust(0, statusBarHeight, 0, 0);
|
||||
m_geometry = fromCGRect([rootView convertRect:m_uiScreen.bounds fromView:m_uiWindow]).toRect();
|
||||
m_availableGeometry = fromCGRect([rootView convertRect:m_uiScreen.applicationFrame fromView:m_uiWindow]).toRect();
|
||||
|
||||
if (m_geometry != previousGeometry || m_availableGeometry != previousAvailableGeometry) {
|
||||
const qreal millimetersPerInch = 25.4;
|
||||
|
Loading…
Reference in New Issue
Block a user