Subview restrictions do not work in iOS 8, XCode 6 (6A313). IOS 7 Works
Just add the subview UIView
from the controller creating with instantiateViewControllerWithIdentifier
to the current view of the controllers and add constraints to maintain the size of the new subview to cover the entire area. The code below worked in iOS 7. iOS 8 allows you to pick up a small portion of the upper left corner. iOS 7 does what I expect, which is the size of the subplot over the entire size of the parent view. I would attach an image, but I don't have one. Setting it translatesAutoresizingMaskIntoConstraints
to YES fixes the problem, but then the view does not respect the constraints and resizes when the orientation is changed or resized.
spotCheckStoresViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"visitStoresViewController"];
spotCheckStoresViewController.mainViewController = self;
spotCheckStoresViewController.dataMode = kDataModeViews;
spotCheckStoresViewController.lastRow = [self getViewsLastRow];
spotCheckStoresViewController.view.tag = -200;
currentView = spotCheckStoresViewController.view;
[self addChildViewController:spotCheckStoresViewController];
[self.view insertSubview:currentView belowSubview:_menuViewController.view];
currentView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:currentView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:currentView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:currentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:currentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]];
//[self.view updateConstraints];
//[self.view layoutIfNeeded];
I tried to set the subquery frame as well. Any ideas that could change in iOS 8 to change the behavior of constraints used in this way?
source to share
In my case, the problem is with the constraints marked with UIView-Encapsulated-Layout-Width
and UIView-Encapsulated-Layout-Height
. When I removed them, everything acted as if my view was size zero, and everything was centered in the upper left corner of the screen. When I left them, the new constraints worked as expected. I also kept the constraints labeled _UILayoutSupportConstraint
.
source to share