summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qioswindow.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-11-20 17:48:49 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-22 22:36:30 +0100
commitae5392a00bdd5a569250cd4e387868141cbd68e9 (patch)
tree322f562d6cd68704a3f19643c39a0fb236f4328d /src/plugins/platforms/ios/qioswindow.mm
parent1ca27d38bc065b124a8fda6548e41f79c351e17d (diff)
iOS: Take position of root viewcontroller into account for geometry changes
When setting the geometry on our UIView, or when reporting it back to Qt in our layoutSubviews callback, we need to take into account that the root viewcontroller may be not be positioned at 0,0 in the screen's window. Even when using the wantsFullScreenLayout property of the view controller this may be the case on iOS7 when the in-call status-bar is visible. Change-Id: I0ca706c1c9aff8ba4f3b4ccdf83dba713bd5c9c2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qioswindow.mm')
-rw-r--r--src/plugins/platforms/ios/qioswindow.mm30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm
index 14220f1139..e835b829a8 100644
--- a/src/plugins/platforms/ios/qioswindow.mm
+++ b/src/plugins/platforms/ios/qioswindow.mm
@@ -178,9 +178,20 @@
// from what we end up with after applying window constraints.
QRect requestedGeometry = m_qioswindow->geometry();
+ QRect actualGeometry;
+ if (m_qioswindow->window()->isTopLevel()) {
+ UIWindow *uiWindow = self.window;
+ CGRect rootViewPositionInRelationToRootViewController =
+ [uiWindow.rootViewController.view convertRect:uiWindow.bounds fromView:uiWindow];
+
+ actualGeometry = fromCGRect(CGRectOffset([self.superview convertRect:self.frame toView:uiWindow.rootViewController.view],
+ -rootViewPositionInRelationToRootViewController.origin.x, -rootViewPositionInRelationToRootViewController.origin.y));
+ } else {
+ actualGeometry = fromCGRect(self.frame);
+ }
+
// Persist the actual/new geometry so that QWindow::geometry() can
// be queried on the resize event.
- QRect actualGeometry = fromCGRect(self.frame);
m_qioswindow->QPlatformWindow::setGeometry(actualGeometry);
QRect previousGeometry = requestedGeometry != actualGeometry ?
@@ -497,9 +508,20 @@ void QIOSWindow::applyGeometry(const QRect &rect)
// The baseclass takes care of persisting this for us.
QPlatformWindow::setGeometry(rect);
- // Since we don't support transformations on the UIView, we can set the frame
- // directly and let UIKit deal with translating that into bounds and center.
- m_view.frame = toCGRect(rect);
+ if (window()->isTopLevel()) {
+ // The QWindow is in QScreen coordinates, which maps to a possibly rotated root-view-controller.
+ // Since the root-view-controller might be translated in relation to the UIWindow, we need to
+ // check specifically for that and compensate.
+ UIWindow *uiWindow = m_view.window;
+ CGRect rootViewPositionInRelationToRootViewController =
+ [uiWindow.rootViewController.view convertRect:uiWindow.bounds fromView:uiWindow];
+
+ m_view.frame = CGRectOffset([m_view.superview convertRect:toCGRect(rect) fromView:m_view.window.rootViewController.view],
+ rootViewPositionInRelationToRootViewController.origin.x, rootViewPositionInRelationToRootViewController.origin.y);
+ } else {
+ // Easy, in parent's coordinates
+ m_view.frame = toCGRect(rect);
+ }
// iOS will automatically trigger -[layoutSubviews:] for resize,
// but not for move, so we force it just in case.