23
votes

A year ago I've seen couple of Apple WWDC keynotes about benefits of Auto Layout, but when I tried them in real world projects, I experienced that when you move some UI element on a Storyboard even slightly, it breaks half of the constraints, nullifying all the benefits of Auto Layout.

Till now I've been utilising Springs & Struts quite successfully, and in conjunction with KVO observing frame path for view, handled most of rotation realignments gracefully, with just couple lines of code.

So now with iOS 7 coming out, I got a question: Can I keep successfully utilising Springs & Struts only for iOS 7 apps and avoid using Auto Layout? Or am I losing out on anything by doing so? Learning and mastering skill of using Auto Layout in different scenarios would probably take couple of days to me, so I'd really appreciate some argumented advice.


RESOLVED: Thanks to Max's answer, I started to dig into Auto Layout; while Null is right in his answer - you actually can use Springs & Struts on iOS 7 without too much trouble, Auto-Layout is powerful.

Apparently in Xcode 5, the following things are fixed:

  • To delete a constraint you don't actually need to perform ancient shamanic dance of rain. You delete it and layout goes into warning mode, indicating issues you need to resolve to make Auto Layout work.

  • When you move things around, your constraints does not change; only view frame in Interface Builder changes.

  • When frame in Interface Builder is actually different from calculated with layout constraints frame, Interface Builder will indicate the runtime frame of that element with red dotted line. Finally it is done right. Thanks, Apple.

  • Here's a link to WWDC 2013 session that demonstrates how to utilise all of that in Xcode 5. You'd need apple developer account to view that.

So my choice now is Auto Layout. Thank you everybody.

3

3 Answers

23
votes

Auto Layout is the future and Springs & Struts is the past. If you continue to use Springs & Struts you will be at a disadvantage as the new standard - Auto Layout - becomes prevalent.

Also, Springs & Struts isn't effective for complex views. Auto Layout is considerably more powerful.

With iOS 7, it's early days, and although I'm not sure exactly what the implications are, the iOS 7 UI Transition Guide specifically mentions that using Auto Layout will ease the transition process:

If your app uses Auto Layout, your job is easier. In Xcode 5, Auto Layout can help an app accommodate new UI element metrics and respond appropriately to dynamic changes in text size. Auto Layout is particularly helpful if you’re transitioning an iOS 6 app or you need to support both iOS 6 and iOS 7.

If you didn’t use Auto Layout, now may be the perfect time to start, especially if you need to support more than one version of an app. If you use manual or programmatic layout techniques, you're responsible for ensuring that the layout adjusts appropriately when text size changes.

Personally, I've been using Auto Layout since Xcode 4.6.3. The initial learning curve is painful, but after that it really becomes a joy to use. I'd definitely never go back to Springs & Struts or manually calculating metrics using frames.

4
votes

Yes you still can use Springs & Struts in iOS7, it works in my beta app although I had a bad time fixing my views but finally it works.

Please consider read the below:

If your application already uses Auto Layout, the development tool that automatically adjusts the layout to user’s viewing device resolution and orientation, your transition to the iOS7 will be fairly straightforward. If not, we recommend you evaluate whether you should start. The biggest reason why you should start is that now with iOS7 the user has the ability to change their text sizing, and your application in turn will be expected to respect this by updating the layout to support the desired text size. If you are using “Springs and Struts” or programmatic layout, then you will need to spend considerable time manipulating the views in order to get your layouts right. This can of course also affect the decision you make to support iOS6.

Reference here.

1
votes

You should use Auto layout due to it's more updated way of using constraints