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
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.
Now just set the value of that constraint to zero (0) by double clicking on it.
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.
And then press Cmd + Alt + = to automatically reposition everything.
Your searchbar should now be pinned to the top and stay there regardless of whether you are in expanded or collapsed iMessage mode.