"Auto Layout Still Required After Executing -layoutSubviews" in UINavigationBar Subclass

I have a subclass of UINavigationBar to which I add some UIViews.

My UIViews are laid out according to the constraints I define in -[UIView updateViewConstraints:]

NSDictionary *views, *metrics;

// search container constraints
[self addSubview:self.searchContainer];
self.searchContainer.translatesAutoresizingMaskIntoConstraints = NO;

views = NSDictionaryOfVariableBindings(_searchContainer);
metrics = @{@"h": @(SearchContainerExpandedHeight) };
self.searchContainerLeftSpacingConstraint = [NSLayoutConstraint constraintWithItem:self.searchContainer attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:xMargin];
[self addConstraint:self.searchContainerLeftSpacingConstraint];
self.searchContainerRightSpacingConstraint = [NSLayoutConstraint constraintWithItem:self.searchContainer attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant: 0 - xMargin];
[self addConstraint:self.searchContainerRightSpacingConstraint];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-24-[_searchContainer(h)]" options:0 metrics:metrics views:views]];
//etc

      

On iOS8 and up, this works fine. On iOS7 I am getting the following error:

'Auto layout is still required after -layoutSubviews. MyUINavigationBarSubclass implementation of -layoutSubviews requires a call to super. '

What gives? Am I not overriding layoutSubviews anywhere?

PS. I tried calling [self layoutIfNeeded] before adding constraints (as some suggested in other questions) but it doesn't seem to work.

+3


source to share


1 answer


Make sure you have installed:

[containerView setTranslatesAutoresizingMaskIntoConstraints:NO]; 

      



for your container and spies.

0


source







All Articles