3
votes

I've got a UINavigationBar subclass to which I am adding some UIViews.

My UIViews are layed-out according to 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 above, this works fine. On iOS7, I am getting the following error:

'Auto Layout still required after executing -layoutSubviews. MyUINavigationBarSubclass's implementation of -layoutSubviews needs to call super.'

What gives? I am not overriding layoutSubviews anywhere?

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

1
So what is DDExpandableSearchBar? - matt
UINavigationBar subclass - Sean Danzeiser
But my point is: it exists. So it is doing something iOS 7 does not like. - matt
I know I am trying to figure out what that is exactly :(. I'm having difficulty adding ANY constraints to a UINavigationBar in iOS7 and below - Sean Danzeiser
You seem to make a habit of having this problem: stackoverflow.com/questions/25573813/… - matt

1 Answers

0
votes

Ensure that you set:

[containerView setTranslatesAutoresizingMaskIntoConstraints:NO]; 

for your container and subviews.