Say you have a SearchBar that you want to pin to the top of your screen and have it stay there regardless of whether you are in collapsed or expanded mode.

Add your search bar, and then control drag a constraint to the top of the view like so

Screen Shot 2017-01-08 at 7.04.42 AM.pngScreen Shot 2017-01-08 at 7.04.48 AM.png

This will add a constraint that will bind the searchbar to the ‘Top Layout Guide’ property of your view controller. Top layout guide is a special property Apple provides to automatically keep your view below nav bars and things like this.

Screen Shot 2017-01-08 at 7.06.22 AM.png

Now just set the value of that constraint to zero (0) by double clicking on it.

Screen Shot 2017-01-08 at 7.07.04 AM.png

Add two more constraints to in the search bar to the sides (click the left and right red bars and then ‘Add 2 constraints’ at the bottom.

Screen Shot 2017-01-08 at 7.08.37 AM.png

Screen Shot 2017-01-08 at 7.09.33 AM.png

And then press Cmd + Alt + = to automatically reposition everything.

Screen Shot 2017-01-08 at 7.10.09 AM.png

Your searchbar should now be pinned to the top and stay there regardless of whether you are in expanded or collapsed iMessage mode.

Screen Shot 2017-01-08 at 7.11.15 AM.png

 

Screen Shot 2017-01-08 at 7.11.22 AM.png