So I just wrote an absolutely superb, perfectly well-designed iPhone app that's going to make so rich, I'll be awash in pontoon boats and swimsuit models and helicopters. I want to make even more cash by converting it to a universal app for both iPad and iPhone.
所以我刚刚写了一个绝对精湛,设计精良的iPhone应用程序,它将变得如此丰富,我将充斥着浮桥船和泳装模特和直升机。我希望通过将其转换为适用于iPad和iPhone的通用应用程序来赚取更多现金。
Now that I'm doing that, and being the lazy programmer I am, trying to maximize reuse of code I've already written, I'm finding I can reuse most of it -- certainly all of the model -- but there's always some little thing that I have to modify on a controller class. Or, there's constant checks on UI_USER_INTERFACE_IDIOM()
which seems like a code smell to me.
既然我正在这样做,而且我是懒惰的程序员,试图最大限度地重用我已经编写的代码,我发现我可以重用大部分代码 - 当然所有的模型 - 但总是我必须在控制器类上修改一些小东西。或者,对UI_USER_INTERFACE_IDIOM()进行持续检查,这对我来说似乎是一种代码味道。
At the same time, I think the iPad version should not be the iPhone version writ large. A different UI is certainly warranted to most cases, but there will be spots where you want to reuse a dialog, or a whole view hierarchy.
与此同时,我认为iPad版本不应该是iPhone版大写。在大多数情况下,肯定会有一个不同的UI,但是有些地方需要重用对话框或整个视图层次结构。
So, I ask the community. What are some good practices to follow to ensure that my app can be universal with minimal tweaks?
所以,我问社区。有哪些好的做法可以确保我的应用程序可以通过最小的调整进行通用?
2 个解决方案
#1
5
Assuming you followed the MVC pattern, M is obviously shared between the iPhone and the iPad (and most of the M⇔C relationship too).
假设您遵循MVC模式,M显然在iPhone和iPad之间共享(以及大多数M⇔C关系)。
Different UI means different V and different V⇔C.
不同的UI意味着不同的V和不同的V⇔C。
A few ideas:
一些想法:
-
If you're into Interface Builder, use 1 nib for the iPhone UI and another one for the iPad.
如果您使用的是Interface Builder,请为iPhone UI使用1个笔尖,为iPad使用另一个笔尖。
-
Have a good understanding of the views' autoresizing mask. With the correct value, you often get rid of a large part of your view layout code.
对视图的自动调整掩码有很好的理解。使用正确的值,您经常会删除大部分视图布局代码。
-
As much as possible, don't use absolute values when manually positioning your views or drawing custom views.
myView.frame = CGRectMake(0,0, 320, 480)
may not do well on the iPad for example.尽可能在手动定位视图或绘制自定义视图时不要使用绝对值。例如,myView.frame = CGRectMake(0,0,320,480)在iPad上可能效果不佳。
-
If you have a development target of at least iOS 3.2, suffix your device-specific resources with
~ipad
or~iphone
. You'll be able to get them using their generic name.如果您的开发目标至少为iOS 3.2,请使用~ipad或~iphone为您的设备特定资源添加后缀。您将能够使用其通用名称获取它们。
Example:
With AwesomeView~ipad.xib
and AwesomeView~iphone.xib
, you could write [[AwesomeViewController alloc] initWithNibName:@"AwesomeView" bundle:nil]
.
Same thing for images (foo~ipad.png
and foo~iphone.png
, then [UIImage imageName:@"foo"]
)
示例:使用AwesomeView~ipad.xib和AwesomeView~iphone.xib,您可以编写[[AwesomeViewController alloc] initWithNibName:@“AwesomeView”bundle:nil]。图像也一样(foo~ipad.png和foo~iphone.png,然后是[UIImage imageName:@“foo”])
I'm pretty sure most of these points are obvious, but they've been quite time-saving for me.
我很确定这些要点中的大部分是显而易见的,但它们对我来说非常节省时间。
#2
2
What I found is that I end up with significantly different UIs for iPhone vs iPad for the same app. The difference in screen real estate and other aspects really ask for different approaches. If nothing else I end up with fewer separate views (screens) for iPad than for iPhone. (I'd love a ride in the helicopter by the way).
我发现,对于同一个应用程序,我最终会为iPhone和iPad提供截然不同的UI。屏幕房地产和其他方面的差异确实需要不同的方法。如果不出意外的话,我最终会为iPad提供比iPhone更少的单独视图(屏幕)。 (顺便说一句,我喜欢骑直升机)。
#1
5
Assuming you followed the MVC pattern, M is obviously shared between the iPhone and the iPad (and most of the M⇔C relationship too).
假设您遵循MVC模式,M显然在iPhone和iPad之间共享(以及大多数M⇔C关系)。
Different UI means different V and different V⇔C.
不同的UI意味着不同的V和不同的V⇔C。
A few ideas:
一些想法:
-
If you're into Interface Builder, use 1 nib for the iPhone UI and another one for the iPad.
如果您使用的是Interface Builder,请为iPhone UI使用1个笔尖,为iPad使用另一个笔尖。
-
Have a good understanding of the views' autoresizing mask. With the correct value, you often get rid of a large part of your view layout code.
对视图的自动调整掩码有很好的理解。使用正确的值,您经常会删除大部分视图布局代码。
-
As much as possible, don't use absolute values when manually positioning your views or drawing custom views.
myView.frame = CGRectMake(0,0, 320, 480)
may not do well on the iPad for example.尽可能在手动定位视图或绘制自定义视图时不要使用绝对值。例如,myView.frame = CGRectMake(0,0,320,480)在iPad上可能效果不佳。
-
If you have a development target of at least iOS 3.2, suffix your device-specific resources with
~ipad
or~iphone
. You'll be able to get them using their generic name.如果您的开发目标至少为iOS 3.2,请使用~ipad或~iphone为您的设备特定资源添加后缀。您将能够使用其通用名称获取它们。
Example:
With AwesomeView~ipad.xib
and AwesomeView~iphone.xib
, you could write [[AwesomeViewController alloc] initWithNibName:@"AwesomeView" bundle:nil]
.
Same thing for images (foo~ipad.png
and foo~iphone.png
, then [UIImage imageName:@"foo"]
)
示例:使用AwesomeView~ipad.xib和AwesomeView~iphone.xib,您可以编写[[AwesomeViewController alloc] initWithNibName:@“AwesomeView”bundle:nil]。图像也一样(foo~ipad.png和foo~iphone.png,然后是[UIImage imageName:@“foo”])
I'm pretty sure most of these points are obvious, but they've been quite time-saving for me.
我很确定这些要点中的大部分是显而易见的,但它们对我来说非常节省时间。
#2
2
What I found is that I end up with significantly different UIs for iPhone vs iPad for the same app. The difference in screen real estate and other aspects really ask for different approaches. If nothing else I end up with fewer separate views (screens) for iPad than for iPhone. (I'd love a ride in the helicopter by the way).
我发现,对于同一个应用程序,我最终会为iPhone和iPad提供截然不同的UI。屏幕房地产和其他方面的差异确实需要不同的方法。如果不出意外的话,我最终会为iPad提供比iPhone更少的单独视图(屏幕)。 (顺便说一句,我喜欢骑直升机)。