将iPhone xib转换为iPad xib?

你怎么做呢? 我看到一个video教程,但屏幕太小。 此外,除了改变视图大小,是否还有其他重大变化,我将不得不使我的iphone应用程序转换为iPad?

假设你已经有了Xcode 3的SDK,

  1. 打开IB。
  2. 打开XIB。
  3. 文件 – >使用自动调整掩码创buildiPad版本。

我能够把它缩小到几个东西,所以这里是为我工作的步骤:

1)复制iPhone xib文件并将其添加到您的项目中

2)右键单击该文件(在xcode中)和打开为>源代码

3)第二行应该是这样的:

<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10"> 

用。。。来代替:

 <archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="7.10"> 

4)search“IBCocoaTouchFramework”并用“IBIPadFramework”replace所有的事件

5)保存文件并打开另存为> Interface Builder – iOS

该文件可能仍然看起来像一个普通的iPhone xib,但是对于我来说,一旦我在属性检查器中将状态栏更改为“黑色”,xib的其余部分只是“咬合”到iPad xib

在Xcode 5中,您应该只是:

找:

 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none"> 

replace为:

 <document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none"> 

请注意,我们只是将.iPad添加到typetargetRuntime属性中。

打开后只需select一个新的尺寸进行调整。 示例:iPad全屏。

XCode4:

在xcode 4中,我们不能为单个xib做到这一点,但我们可以一次创build各自的ipad版本。

在configuration你的项目到ipad之前,当它只configuration为iphone,右键单击目标并单击重复。

现在select“复制并转换到ipad”。创build一个新的目标和新的xib集合,减less一些工作。

希望能帮助到你。

Xcode 4

从Xcode 4中删除了“ 使用自动调整面具创buildiPad版”function。现在最简单的方法是使用Xcode 3进行转换,因为nib(.xib)文件格式没有改变。

Xcode 3&4现在可以安装在同一个系统上,只需select一个不同的文件夹(请参阅磁盘映像上的安装说明)。

否则,您将需要从iPhone版本复制/粘贴UI元素,并将其重新链接到您的代码。

让电脑做计算机的工作呢?
更快,错误的风险更小。

这是一个基于Jag优秀的答案的工作stream程,但是通过sed自动化。

首先,我们来设置一些东西。 我们只需要做一次。
在包含您的XIB的目录中,使用以下内容创build两个文件:

文件iPhoneToiPadXIBConversion.sed

 s/com.apple.InterfaceBuilder3.CocoaTouch.XIB/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/g s/IBCocoaTouchFramework/IBIPadFramework/g 

和文件iPadToiPhoneXIBConversion.sed

 s/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/com.apple.InterfaceBuilder3.CocoaTouch.XIB/g s/IBIPadFramework/IBCocoaTouchFramework/g 

安装程序现在完成。 要转换XIB,请在terminal中input以下两个命令之一:

iPhone到iPad转换:

 sed -f iPhoneToiPadXIBConversion.sed MyViewController~iphone.xib > MyViewController.xib 

iPad到iPhone的转换:

 sed -f iPadToiPhoneXIBConversion.sed MyViewController.xib > MyViewController~iphone.xib 


为了好玩,让我们在zsh中创build两个函数,使转换更加简单:

 function convertiPadXIBToiPhone () { newXibName=`echo "$1" | /usr/bin/sed "s/.xib/~iphone.xib/"` `/usr/bin/sed -f iPadToiPhoneXIBConversion.sed "$1" > "$newXibName"` echo "Did convert $1 to $newXibName." } function convertiPhoneXIBToiPad () { newXibName=`echo "$1" | /usr/bin/sed "s/~iphone.xib/.xib/"` `/usr/bin/sed -f iPhoneToiPadXIBConversion.sed "$1" > "$newXibName"` echo "Did convert $1 to $newXibName." } 

把这个添加到你的zshconfiguration之后,转换一个XIB是很简单的:

 convertiPadXIBToiPhone MyViewController.xib 

要么

 convertiPhoneXIBToiPad MyViewController.xib 

使用“查看源代码”打开XCode 4中的XIB。

之前

备份有问题的笔尖。

用这个傀儡代替

  <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string> <integer value="1056" key="NS.object.0"/> </object> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string> <integer value="3100" key="NS.object.0"/> </object> <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> <int key="IBDocument.defaultPropertyAccessControl">3</int> <string key="IBCocoaTouchPluginVersion">301</string> 

为这个其他咕

  <string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string> <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string> <integer value="3100" key="NS.object.0"/> </object> <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> <int key="IBDocument.defaultPropertyAccessControl">3</int> <string key="IBCocoaTouchPluginVersion">301</string> 

然后,对于使用集成IB的笔尖中的每个视图,将其删除,然后点击撤消。

然后淋浴在热水中,消除你可能有的恶心的感觉。

您可以以文本文件的forms打开XIB并更改UIView大小:

右键单击导航器中的XIB文件,然后select“打开为…”作为源文件打开。

findUIView参考并更改帧值:

 <object class="IBUIView" id="191373211"> <string key="NSFrame">{{0, 20}, {768, 1024}}</string> 

在XCode 4.3.2中,创buildipib版本xib的最简单方法是复制该xib文件,并将〜ipad后缀添加到文件名中。 并将“myVC.xib”和“myVC〜ipad.xib”添加到您的项目中。 请注意,它是“〜ipad”不是“〜iPad”。 在iPad上运行时,您的应用程序将自动使用该〜ipad版本。 这也适用于资源文件(如图像)。

目前我可以find的最佳参考… https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html

Xcode 5更新

targetRuntime = “iOS.CocoaTouch”

targetRuntime = “iOS.CocoaTouch.iPad”

我将logging我在Xcode 4.5中做了什么:

  1. fixpattern.sh

     cp REPLACEME_Iphone.h REPLACEME_Ipad.h sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.h > REPLACEME_Ipad_tmp.h mv REPLACEME_Ipad_tmp.h REPLACEME_Ipad.h cp REPLACEME_Iphone.m REPLACEME_Ipad.m sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.m > REPLACEME_Ipad_tmp.m mv REPLACEME_Ipad_tmp.m REPLACEME_Ipad.m cp REPLACEME_Iphone.xib REPLACEME_Ipad.xib sed -e 's/com.apple.InterfaceBuilder3.CocoaTouch.XIB /com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib sed -e 's/IBCocoaTouchFramework/IBIPadFramework/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib sed -e 's/320, 416/768, 1004/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib sed -e 's/REPLACEME_Iphone/REPLACEME_Ipad/g' REPLACEME_Ipad.xib > REPLACEME_Ipad_tmp.xib mv REPLACEME_Ipad_tmp.xib REPLACEME_Ipad.xib 
  2. 创build一个你想在fixfile转换的文件列表,每一行将是一个没有扩展名的文件名。 如果您的原始文件名是AAA_Iphone.h ,只需放入AAA 。 如果您的原始文件不是这种模式,则需要修改脚本。

  3. 在命令行中运行

     cat fixfile | while read line ; do sed -e "s/REPLACEME/${line}/g" fixpattern.sh ; done > fixall.sh 
  4. 查看并运行fixall.sh

  5. 将新创build的文件添加到项目中

杰格的答案很好。 但是,如果在Xcode 5中打开/创buildXIB,则会出现问题。

对于Xcode 5

1)复制iPhone xib文件并将其添加到您的项目中

2)右键单击该文件(在xcode中)和打开为>源代码

3)第二行应该是这样的:

 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" 

改变它

 <document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4510" 

4)第8行应该是这样的:

 <rect key="frame" x="0.0" y="0.0" width="320" height="480"/> 

改变它

 <rect key="frame" x="0.0" y="64" width="768" height="960"/> 

就是这样,你有iPad XIB。 但是Jag仍然是真正的荣誉。

除了Jag给出的答案之外,还search“320,460”并将其replace为768,1024,您的XIB将被调整为iPad尺寸。

对于Xcode 4,

您无需为每个设备创build单独的目标。 相反,您可以将项目摘要中的“设备”更改为“通用”,而“通用”已经在iPhone中。 这在更新iOS 5应用程序到Universal Xcode 4.2的链接中得到了解答。 因此,它会为你做转换。

听起来像最好的解决scheme是总是作为iphone开发,然后一旦完成,添加ipad目标,让xcode做更新。 我犯了同样的错误,select通用启动,它创build了前几个文件,但其他每个xib都必须在ipad文件夹中手动重新创build。 大疼

 Jag has given Great Answer. 

在某些情况下。

无需在Ipad XIB中转换您的Iphone XIB。 您可以使用Autoresizingmask并获取运行Ipad。 只需要configuration您的应用程序运行在通用模式与适当的autoresizingmask。