From def8b43daa181a5edc6e82fbaa2ac98960fa70da Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 31 Jul 2018 14:28:41 -0600 Subject: [PATCH] iOS9/10 fixups --- .../HomeView/HomeViewController.m | 6 +++++- .../ViewControllers/OWSNavigationController.m | 15 ++------------ SignalMessaging/Views/OWSNavigationBar.swift | 20 +++++++++++++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 4249fe394..49e95f7bd 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -418,7 +418,11 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self addChildViewController:searchResultsController]; [self.view addSubview:searchResultsController.view]; [searchResultsController.view autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop]; - [searchResultsController.view autoPinTopToSuperviewMarginWithInset:56]; + if (@available(iOS 11, *)) { + [searchResultsController.view autoPinTopToSuperviewMarginWithInset:56]; + } else { + [searchResultsController.view autoPinToTopLayoutGuideOfViewController:self withInset:40]; + } searchResultsController.view.hidden = YES; [self updateBarButtonItems]; diff --git a/SignalMessaging/ViewControllers/OWSNavigationController.m b/SignalMessaging/ViewControllers/OWSNavigationController.m index 4fa9f5853..7a9d3e17e 100644 --- a/SignalMessaging/ViewControllers/OWSNavigationController.m +++ b/SignalMessaging/ViewControllers/OWSNavigationController.m @@ -141,20 +141,9 @@ NS_ASSUME_NONNULL_BEGIN // in iOS11 we have to ensure the navbar frame *in* layoutSubviews. [navbar layoutSubviews]; } else { - // Pre iOS11 we size the navbar, and position it vertically once. + // in iOS9/10 we only need to size the navbar once [navbar sizeToFit]; - - if (OWSWindowManager.sharedManager.hasCall) { - CGRect oldFrame = navbar.frame; - CGRect newFrame = oldFrame; - newFrame.size.height = navbar.callBannerHeight; - navbar.frame = newFrame; - } else { - CGRect oldFrame = navbar.frame; - CGRect newFrame - = CGRectMake(oldFrame.origin.x, navbar.statusBarHeight, oldFrame.size.width, oldFrame.size.height); - navbar.frame = newFrame; - } + [navbar layoutIfNeeded]; // Since the navbar's frame was updated, we need to be sure our child VC's // container view is updated. diff --git a/SignalMessaging/Views/OWSNavigationBar.swift b/SignalMessaging/Views/OWSNavigationBar.swift index 04014a96d..c05a63ded 100644 --- a/SignalMessaging/Views/OWSNavigationBar.swift +++ b/SignalMessaging/Views/OWSNavigationBar.swift @@ -94,11 +94,18 @@ public class OWSNavigationBar: UINavigationBar { if #available(iOS 11, *) { return super.sizeThatFits(size) - } else { - // pre iOS11, sizeThatFits is repeatedly called to determine how much space to reserve for that navbar. + } else if #available(iOS 10, *) { + // iOS10 + // sizeThatFits is repeatedly called to determine how much space to reserve for that navbar. // That is, increasing this causes the child view controller to be pushed down. // (as of iOS11, this is not used and instead we use additionalSafeAreaInsets) return CGSize(width: fullWidth, height: navbarWithoutStatusHeight + statusBarHeight) + } else { + // iOS9 + // sizeThatFits is repeatedly called to determine how much space to reserve for that navbar. + // That is, increasing this causes the child view controller to be pushed down. + // (as of iOS11, this is not used and instead we use additionalSafeAreaInsets) + return CGSize(width: fullWidth, height: navbarWithoutStatusHeight + callBannerHeight + 20) } } @@ -108,15 +115,16 @@ public class OWSNavigationBar: UINavigationBar { return } + guard #available(iOS 11, *) else { + super.layoutSubviews() + return + } + self.frame = CGRect(x: 0, y: callBannerHeight, width: fullWidth, height: navbarWithoutStatusHeight) self.bounds = CGRect(x: 0, y: 0, width: fullWidth, height: navbarWithoutStatusHeight) super.layoutSubviews() - guard #available(iOS 11, *) else { - return - } - // This is only necessary on iOS11, which has some private views within that lay outside of the navbar. // They aren't actually visible behind the call status bar, but they looks strange during present/dismiss // animations for modal VC's