View iOS size with auto layout enabled

Task

I have the following view, which includes the navigation bar, search bar and table view - the left image is the given view that I have, and what I want to achieve is correct - basically just hide the navigation bar and resize all.

givenwanted

Current solution

Currently, I have managed to hide and resize everything using the vertical space limit from the search box to the top topview property -

  • The default constraint constant is 44 (navigation bar height)
  • After clicking the search box, I hide the navigation bar and set the restriction constant to 0
  • When I stop searching, I restore the navigation bar and set the limit to 44 again.

vertical-constraint

What I want

I'm looking for the easiest way to hide the navigation bar and resize the search box + tables to fill the entire screen.

Is there any way to do this and use the iOS 6 auto-layout system?

My current solution seems unnatural.

+6
source share
2 answers

If this is the only restriction you need to change, you can create an IBOutlet for this restriction in your view or view controller, and then just change the restriction based on when you need to change it:

if(shouldHide){ self.nibTitleBarConstraint.constant = 0.f; } else{ self.nibTitleBarConstraint.constant = 44.f; } 

If you want to animate this change, just insert -layoutIfNeeded in the animation context:

 [UIView animateWithDuration:0.33f animations:^{ [view layoutIfNeeded]; }]; 

This applies to any constraint constant that you would like to change (height, top space, etc.), as long as your other constraints do not know how to react with changing constraints of this kind.

+6
source

You can simply:

 [[self navigationController] setNavigationBarHidden:YES animated:NO]; 
+1
source

All Articles