2

I am using Xcode 6 and iOS 8. The project was written starting at iOS 5, not using Auto Layout. So there is plenty of auto resizing and plenty of code that moves controls and view by manipulating their frames.

I know it works to use both, but do you do a complete conversion, and eliminate every reference to a frame property, or just leave the ones that work?

For example, creating a control on the fly that will be placed in a view but doesn't need its position manipulated once there. Would you get rid of the initWithFrame: and do it all by constraints, or just leave it?

It seems to me that both can coexist, as long as the control is static once created and placed.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
mickm
  • 515
  • 2
  • 11
  • 20

1 Answers1

4

You can mix autolayout and frame code in the same project and even in the same view controller. How you migrate to using only autolayout is up to you. How much time do you have? How complicated is the existing frame code to maintain?

The approach we took in our app is to create a storyboard and add view controllers to it. We mapped these to our existing VC classes and then tested how they looked.

We began replacing views created in code with views in the storyboard, using constraints to position them. For table views, we replaced a lot of ugly .xib files that defined custom cells with prototype cells in the storyboard. We also replaced table headers and footers with views in the storyboard.

We found it usually worked best to convert an entire view controller to an all autolayout approach, removing any use of frames. A few view controllers had very complex frame logic which we left alone - we didn't even define these ones in our storyboard.

In all, we migrated some 25 or 30 view controllers to storyboards, and we got pretty good at it. I'm a big fan of storyboards and autolayout despite occasional head scratchers. It made our transition to larger devices quite smooth.

Mike Taverne
  • 9,156
  • 2
  • 42
  • 58
  • 1
    thanks for the answer. i figured it was along these lines, but wanted to get an idea of what others are doing. we have the same situation; a few controllers with lots of code adjusting frames, and i assume that some of that will be left, and most will be converted. – mickm Oct 27 '14 at 17:31