diff --git a/AsyncDisplayKit/ASViewController.mm b/AsyncDisplayKit/ASViewController.mm index bfdaefbe7c..d18621942c 100644 --- a/AsyncDisplayKit/ASViewController.mm +++ b/AsyncDisplayKit/ASViewController.mm @@ -88,19 +88,7 @@ [super viewWillLayoutSubviews]; [_node measureWithSizeRange:[self nodeConstrainedSize]]; - if (!AS_AT_LEAST_IOS9) { - [self _legacyHandleViewDidLayoutSubviews]; - } -} - -- (void)_legacyHandleViewDidLayoutSubviews -{ - // In modal presentation the view does not automatic resize in iOS7 and iOS8. As workaround we adjust the frame of the - // view manually - if (self.presentingViewController != nil) { - CGSize maxConstrainedSize = [self nodeConstrainedSize].max; - _node.frame = (CGRect){.origin = CGPointZero, .size = maxConstrainedSize}; - } + [self _legacyHandleViewDidLayoutSubviewsIfNecessary]; } - (void)viewDidLayoutSubviews @@ -197,13 +185,27 @@ ASVisibilityDepthImplementation; } } +- (ASInterfaceState)interfaceState +{ + return _node.interfaceState; +} + +#pragma mark - Legacy Layout Handling + +- (BOOL)_shouldLayoutTheLegacyWay +{ + BOOL isModal = (self.presentingViewController != nil && self.presentedViewController == nil); + BOOL isRootViewController = self.view.window.rootViewController == self; + return isModal || isRootViewController; +} + - (ASSizeRange)_legacyConstrainedSize { // In modal presentation the view does not have the right bounds in iOS7 and iOS8. As workaround using the superviews // view bounds UIView *view = self.view; CGSize viewSize = view.bounds.size; - if (self.presentingViewController != nil) { + if ([self _shouldLayoutTheLegacyWay]) { UIView *superview = view.superview; if (superview != nil) { viewSize = superview.bounds.size; @@ -212,9 +214,18 @@ ASVisibilityDepthImplementation; return ASSizeRangeMake(viewSize, viewSize); } -- (ASInterfaceState)interfaceState +- (void)_legacyHandleViewDidLayoutSubviewsIfNecessary { - return _node.interfaceState; + if (AS_AT_LEAST_IOS9) { + return; + } + + // In modal presentation or as root viw controller the view does not automatic resize in iOS7 and iOS8. + // As workaround we adjust the frame of the view manually + if ([self _shouldLayoutTheLegacyWay]) { + CGSize maxConstrainedSize = [self nodeConstrainedSize].max; + _node.frame = (CGRect){.origin = CGPointZero, .size = maxConstrainedSize}; + } } #pragma mark - ASEnvironmentTraitCollection