Fix sizing of root node in ASViewController for modal presentation and root view controller

This commit is contained in:
Michael Schneider
2016-07-14 06:14:25 -07:00
parent 09d1c06f68
commit 6e8772a68d

View File

@@ -88,19 +88,7 @@
[super viewWillLayoutSubviews]; [super viewWillLayoutSubviews];
[_node measureWithSizeRange:[self nodeConstrainedSize]]; [_node measureWithSizeRange:[self nodeConstrainedSize]];
if (!AS_AT_LEAST_IOS9) { [self _legacyHandleViewDidLayoutSubviewsIfNecessary];
[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};
}
} }
- (void)viewDidLayoutSubviews - (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 - (ASSizeRange)_legacyConstrainedSize
{ {
// In modal presentation the view does not have the right bounds in iOS7 and iOS8. As workaround using the superviews // In modal presentation the view does not have the right bounds in iOS7 and iOS8. As workaround using the superviews
// view bounds // view bounds
UIView *view = self.view; UIView *view = self.view;
CGSize viewSize = view.bounds.size; CGSize viewSize = view.bounds.size;
if (self.presentingViewController != nil) { if ([self _shouldLayoutTheLegacyWay]) {
UIView *superview = view.superview; UIView *superview = view.superview;
if (superview != nil) { if (superview != nil) {
viewSize = superview.bounds.size; viewSize = superview.bounds.size;
@@ -212,9 +214,18 @@ ASVisibilityDepthImplementation;
return ASSizeRangeMake(viewSize, viewSize); 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 #pragma mark - ASEnvironmentTraitCollection