这是创建通用 iOS 应用程序的正确方法吗? Xcode 4 - 似乎可以工作?

发布于 2024-12-03 04:18:57 字数 1146 浏览 3 评论 0原文

以下是我如何从现有 iPhone 项目创建通用应用程序,方法是使用重复项创建 ~ipad.xib,然后将它们添加回项目的备份中,并检查通用性。

我使用了 xcode 4.02,基础 sdk 为 4.3.3,部署目标为 3.1.2。

  1. 将整个项目备份到某个地方。
  2. 右键单击 iPhone 目标并选择复制。选择 iPad 的复制而不是仅仅复制。这会创建一个名为 Resources-iPad 的新文件夹,该文件夹下有一个名为 classes 的子文件夹,该子文件夹下是整个项目中所有 xib 文件的副本。 (有趣的是,当我在 Finder 中查看这些文件时,它们没有 .xib 扩展名,尽管它们在 xcode 窗口中显示了扩展名 - 为什么?尽管如此,Finder 仍然说它们是 xib 文件。)
  3. 此时我有两个目标。这似乎是错误的,所以我去查找器并制作了新的 Resources-iPad 文件夹的备份副本,然后删除了整个项目。
  4. 复制回我在步骤 1 中备份的原始 iPhone 项目。
  5. 添加备份的 Resources-iPad 文件夹,并对其进行编辑,使它们看起来适合 iPad。
  6. 我现在有了一个看起来不错的目标,并且我在目标摘要中将其设为通用设备而不是 iPhone。
  7. 但是,在部署到模拟器或设备时,我的行为不一致 - 有时会无缘无故地使用错误的 xib。
  8. 这修复了它 - 在 xcode 中,在 Resources-iPad/classes 文件夹中,将 ipad 的所有 xib 从 mynibname.xib 重命名为 mynibname~ipad.xib (前面的 tilda 且全部小写)

我找不到任何关于它是否是的文档可以这样做。到目前为止,它可以在以下物理设备上运行:

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

这是创建通用应用程序的正确方法吗?现在我已经解决了这个问题,这似乎很容易,但花了很长时间才找到这些信息。哦,我也没有 mainwindow.xib,但其他笔尖在其他地方作为表格视图部分标题和选项卡栏应用程序中的详细视图加载 - 所以我将主界面部分留空。

哦 - 我没有 iPad 1,无法在该设备上进行测试,但它似乎无法在 iPad 3.2 模拟器中正常工作,但所有其他设备和模拟器似乎都可以正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2024-12-10 04:18:57

我看到很多人所做的就是为每个设备使用 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< /强>。

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

What I have seen a lot of people do is use 2 separate classes for each device. Why? Couldn't tell you!

What I do is use 1 class for both iPad and iPhone, only I use a macro to determine what the current device is:

For Example

#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. */
}

Of course, you will need to create iPad versions of your Interfaces, but that is the easy part.

As far as identifying it as a Universal app, there is an option in your Project settings, as well as Target Device Family in build settings that you will make sure is set to iPhone/iPad.

That is pretty much all I do to make universal apps, and is quite less time consuming as writing specific classes for each device!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文