From 839a1d04177abb47ead31103da14faefdb02c584 Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Mon, 2 Nov 2015 21:09:17 -0800 Subject: [PATCH] iOS: fixed #774 (story page position after activating) Now re-activates without story page glitches, and handles rotation while inactive properly. --- .../ios/Classes/NBContainerViewController.m | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/clients/ios/Classes/NBContainerViewController.m b/clients/ios/Classes/NBContainerViewController.m index cf0b423a8..0965fac2c 100644 --- a/clients/ios/Classes/NBContainerViewController.m +++ b/clients/ios/Classes/NBContainerViewController.m @@ -57,6 +57,7 @@ @property (readwrite) BOOL feedDetailIsVisible; @property (readwrite) BOOL keyboardIsShown; @property (readwrite) UIDeviceOrientation rotatingToOrientation; +@property (nonatomic) UIBackgroundTaskIdentifier reorientBackgroundTask; @property (nonatomic, strong) UIPopoverController *popoverController; @@ -222,11 +223,26 @@ [self layoutFeedDetailScreen]; } if (self.feedDetailIsVisible) { - [self.storyPageControl reorientPages]; + // Defer this in the background, to avoid misaligning the detail views + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + self.reorientBackgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + [[UIApplication sharedApplication] endBackgroundTask:self.reorientBackgroundTask]; + self.reorientBackgroundTask = UIBackgroundTaskInvalid; + }]; + [self performSelector:@selector(delayedReorientPages) withObject:nil afterDelay:0.5]; + } else { + [self.storyPageControl reorientPages]; + } } }]; } +- (void)delayedReorientPages { + [self.storyPageControl reorientPages]; + [[UIApplication sharedApplication] endBackgroundTask:self.reorientBackgroundTask]; + self.reorientBackgroundTask = UIBackgroundTaskInvalid; +} + - (NSInteger)masterWidth { UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationIsLandscape(orientation)) {