1

Here is how I made a universal app from an existing iPhone project by creating ~ipad.xib(s) using duplicate and then adding them back to a backup of the project, and checking universal.

I used xcode 4.02 with a base sdk of 4.3.3 with a deployment target of 3.1.2.

  1. Back up your whole project somewhere.
  2. Right click on iPhone target and choose duplicate. Choose duplicate for iPad rather than just duplicate. This makes a new folder called Resources-iPad with a subfolder called classes under that, and under that are copies of all the xib files in the entire project. (The funny thing is that when I look at these files in finder they don't have an .xib extension although they show an extension in the xcode window - why? Finder still says they are xib files anyway though.)
  3. At this point I had two targets. This seemed wrong so I went to finder and made a backup copy of the new Resources-iPad folder, and then deleted the whole project.
  4. Copy back the original iPhone project I had backed up up in step 1.
  5. Added the Resources-iPad folder that was backed up, and edited them so they looked good for iPad.
  6. I now had one target which seemed good, and I made it a universal device instead of iPhone in the target summary.
  7. However, I got inconsistent behavior when deploying to the simulator or device - sometimes the wrong xib would be used for no apparent reason.
  8. This fixed it - in xcode, in the Resources-iPad/classes folder rename all the xibs for ipad from mynibname.xib to mynibname~ipad.xib (tilda in front and all lowercase)

I couldn't find any documentation on whether it is OK to do it this way. It works on these physical devices so far:

iPad 2 with 4.3, iPod touch v1 with 3.1.2, iPod touch v4 (retina) with 4.1

Is this a correct way of creating a universal app? It seems easy enough now that I have this worked out, but took forever to find this info. Oh also I do not have a mainwindow.xib but other nibs that get loaded elsewhere as tableview section headers and detail views in a tabbar app - so I left the main interface sections blank.

Oh - I don't have an iPad 1 and cant test on that device, but it doesn't seem to work right in the iPad 3.2 Simulator, but all other devices and simulators appear to work OK.

4

1 回答 1

2

我看到很多人做的是为每个设备使用 2 个单独的类。为什么?不能告诉你!

我所做的是为 iPad 和 iPhone 使用 1 类,只有我使用宏来确定当前设备是什么:

例如

#define IDIOM           UI_USER_INTERFACE_IDIOM()
#define IPAD            UIUserInterfaceIdiomPad   

if (IDIOM == IPAD)
{
    /* do something specific for iPad. */
} else {
    /* do something specific for iPhone, like set up frames. */
}

当然,您将需要创建您的界面的 iPad 版本,但这是容易的部分。

至于将其识别为通用应用程序,您的项目设置中有一个选项,以及构建设置中的目标设备系列,您将确保将其设置为iPhone/iPad

这几乎是我制作通用应用程序所做的所有工作,并且为每个设备编写特定类所花费的时间要少得多!

于 2011-09-06T23:30:01.810 回答