Is there more efficient way to downscale an iPad application that doesn't use .xib or .storyboard to iPhone scale?

StackOverflow https://stackoverflow.com/questions/20574867

Pregunta

I'm starting an investigation into downscaling an iPad application to fit into the form factor of the iPhone. The main problem is that this project does NOT use .storyboards or .xib files with the exception of a custom UIInputView.

My main question revolves around layout (obviously). Since all of the frame values are in the code, what is the best (shortest) way to allow for multiple different frames based on the total frame size?

I know this is very easy in a storyboard, but due to multiple developers and the use of SVN, we had to forgo the use of them during initial development. I'm not seeing many resources on some google queries on the subject, most developers are going from iPhone -> iPad and not the reverse.

I know about this code:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

But I don't want to have do this for 500+ places in code where we set somethings' frame.

Would it be more efficient to extract all of the frame definitions to a class for retrieving device specific frame sizes?

Some additional notes, We're not using anything iPad specific other than popovers. The entire interface is mostly nested UIViews on one main UIViewController.

¿Fue útil?

Solución

This is exactly one of the types of things that Auto Layout was meant to solve. Behind the scences, everything is using Auto Layout now, but if you have a lot of hardcoded constant values for sizes, you're in for a lot of work to actually take advantage of its new features.

If you want to avoid storyboards/xibs, I suggest considering refactoring your code not to use static sizes via frames/bounds (i.e. a lot of initWithFrame calls), but rather use Visual Format Language where ever you can, and dropping down to full on NSLayoutConstraints as needed.

You'll want to read and understand this: Working with Auto Layout Programmatically

With VFL, you can express virtually all of your sizes and positions as relative values. Where you cannot, you can pass in metrics to your VFL calls with the values that need to be explicitly set for iPad v. iPhone (where relative, calculated values do not work).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top