Experiences with Constraints and Storyboards


Well, it was a challenge, but I got it done. This past weekend I spent most of the time refactoring my personal app to using iOS 6.1’s autolayout capabilities. While I started off pulling out my hair, I ended the weekend with screens that looked pretty good, and that correctly handled almost everything I could throw at it. The net of all of this, is that I learned how to improve the flexibility of my apps. (I now can correctly re-size between iPhone 5 and pre-iPhone 5 layouts).

The biggest problem when going thru this, was that XCode kept trying to guess what I was trying to do. It would pin objects to the top of the screen, which would then disappear beyond the bottom of the screen when I rotated the screen. It would link two assets and then assume that I wanted the same spacing when I rotated, again pushing things around. The biggest thing I learned was to treat your screen layout like a bunch of sub-views. This allows you to then group things in subviews and build up relationships between the subviews. It reminded me of hand coding websites years ago, right after HTML introduced tables.

The other key thing to do, is make sure you pay attention to Less than, Equal, and Greater than. This impacts how things will grow or shrink. I cannot tell you how many times I caught myself with a Equal link(the default), when I wanted things to shrink down, a Less Than link. So far I have not gone into the details of code centric autolayouts, but for my simple app, I didn’t need that yet.

I can try and address questions if you have any, so drop a comment to the blog!