From f14d86c0f9fee9e5c52a5d1e857eb19c93cfed7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 28 Jul 2014 16:24:11 +0200 Subject: [PATCH] iOS: Reflect changes in statusbar height as QScreen availableGeometry We detect changes to the statusbar height, eg. when the in-call 40px tall statusbar is active, and ensure that the root viewcontroller view is laid out again with new screen properties applied. To make the layout match the animation of the statusbar height we apply the layout inside a animation block. Change-Id: I751d9d1273e833ef052a3a4f3d2777e1dffec7dd Reviewed-by: Richard Moe Gustavsen --- .../platforms/ios/qiosviewcontroller.mm | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index 7079cd73eb..9a5d5c3691 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -155,6 +155,22 @@ self.view = [[[QIOSDesktopManagerView alloc] init] autorelease]; } +- (void)viewDidLoad +{ + [super viewDidLoad]; + + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserver:self selector:@selector(willChangeStatusBarFrame:) + name:UIApplicationWillChangeStatusBarFrameNotification + object:[UIApplication sharedApplication]]; +} + +- (void)viewDidUnload +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil]; + [super viewDidUnload]; +} + -(BOOL)shouldAutorotate { // Until a proper orientation and rotation API is in place, we always auto rotate. @@ -179,6 +195,26 @@ } #endif +- (void)willChangeStatusBarFrame:(NSNotification*)notification +{ + Q_UNUSED(notification); + + if (self.view.window.screen != [UIScreen mainScreen]) + return; + + // UIKit doesn't have a delegate callback for statusbar changes that's run inside the + // animation block, like UIViewController's willAnimateRotationToInterfaceOrientation, + // nor does it expose a constant for the duration and easing of the animation. However, + // though poking at the various UIStatusBar methods, we can observe that the animation + // uses the default easing curve, and runs with a duration of 0.35 seconds. + static qreal kUIStatusBarAnimationDuration = 0.35; + + [UIView animateWithDuration:kUIStatusBarAnimationDuration animations:^{ + [self.view setNeedsLayout]; + [self.view layoutIfNeeded]; + }]; +} + - (void)viewWillLayoutSubviews { if (!QCoreApplication::instance())