这是创建通用iOS应用的正确方法吗? Xcode 4-似乎可以工作? [英] Is this a correct way of creating a universal iOS app? Xcode 4 - Seems to work?

查看:81
本文介绍了这是创建通用iOS应用的正确方法吗? Xcode 4-似乎可以工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我使用的xcode 4.02的基本sdk为4.3.3,部署目标为3.1.2.

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

  1. 将整个项目备份到某个地方.
  2. 右键单击iPhone目标并选择重复项.为iPad选择重复项,而不只是重复项.这将创建一个名为Resources-iPad的新文件夹,该文件夹下有一个名为类的子文件夹,该子文件夹下是整个项目中所有xib文件的副本. (有趣的是,当我在finder中查看这些文件时,它们没有.xib扩展名,尽管它们在xcode窗口中显示了扩展名-为什么?Finder仍然说它们还是xib文件.)
  3. 这时我有两个目标.这似乎是错误的,所以我去了finder并制作了新的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且全部小写)

我找不到任何文档来确定是否可以通过这种方式进行操作.到目前为止,它可以在这些物理设备上运行:

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

具有4.3的iPad 2,具有3.1.2的iPod touch v1,具有4.1的iPod touch v4(视网膜)

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

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

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.

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

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.

推荐答案

我见过很多人做的是为每个设备使用2个单独的类.为什么?无法告诉你!

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

我要做的是在iPad和iPhone上都使用1类,只有我使用一个宏来确定当前设备是什么:

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

#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版本的Interfaces,但这很容易.

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

就将其识别为通用应用程序而言,您的项目设置以及构建设置中的 Target Device Family (目标设备系列)中都有一个选项,您可以确保将其设置为 iPhone /iPad .

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!

这篇关于这是创建通用iOS应用的正确方法吗? Xcode 4-似乎可以工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆