ios 将 iPhone xib 转换为 iPad xib?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2488280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting iPhone xib to iPad xib?
提问by NextRev
How do you do it? I saw one video tutorial on it, but the screen was too small. Also, other than changing the view size, are there any other major changes I would have to make to my iphone apps to convert to iPad?
你怎么做呢?我看过一个视频教程,但屏幕太小了。另外,除了更改视图大小之外,我还需要对我的 iphone 应用程序进行任何其他重大更改才能转换为 iPad 吗?
采纳答案by kennytm
Assume you've the SDK with Xcode 3,
假设您拥有带有 Xcode 3的 SDK ,
- Open IB.
- Open the XIB.
- File -> Create iPad version using autoresizing masks.
- 打开IB。
- 打开 XIB。
- 文件 -> 使用自动调整大小蒙版创建 iPad 版本。
回答by Jag
I was able to narrow it down to a few things, so here are the steps that worked for me:
我能够将其缩小到几件事,因此以下是对我有用的步骤:
1) Make a copy of the iPhone xib file and add it to your project
1) 复制 iPhone xib 文件并将其添加到您的项目中
2) Right click the file (in xcode) and Open As > Source Code
2)右键单击文件(在xcode中)并打开为>源代码
3) The 2nd line should look like:
3)第二行应该是这样的:
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
Replace with:
用。。。来代替:
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="7.10">
4) Search for "IBCocoaTouchFramework" and Replace all occurrences with "IBIPadFramework"
4)搜索“IBCocoaTouchFramework”,并以“IBIPadFramework”全部替换
5) Save the file and Open As > Interface Builder - iOS
5) 保存文件并打开为 > Interface Builder - iOS
The file might still look like a regular iPhone xib, but for me, once I changed the Status Bar to "Black" in the Attributes inspector the rest of the xib just kind of "snapped" into an iPad xib
该文件可能仍然看起来像一个普通的 iPhone xib,但对我来说,一旦我在属性检查器中将状态栏更改为“黑色”,xib 的其余部分就会“卡入”到 iPad xib
回答by SebastianView
In Xcode 5 you should just:
在 Xcode 5 中,您应该:
Find:
找:
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
Replace by:
替换为:
<document type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none">
Note we are just adding .iPadto the type
and targetRuntime
properties.
请注意,我们只是将.iPad添加到type
和targetRuntime
属性。
After opening just select a new Size to adjust. Example: iPad Full Screen.
打开后只需选择一个新的尺寸进行调整。示例:iPad 全屏。
回答by Tejesh Alimilli
XCode4:
XCode4:
In xcode 4 we can't do that for a single xib,but we can create respective ipad versions all at once.
在 xcode 4 中,我们无法为单个 xib 执行此操作,但我们可以同时创建相应的 ipad 版本。
Before configuring your project to ipad,when it is configured only for iphone, right click on target and click on duplicate.
在将您的项目配置到 ipad 之前,当它仅配置为 iphone 时,右键单击目标并单击复制。
Now select "duplicate and transition to ipad".A new target and new set of xibs are created.It should reduce some work.
现在选择“复制并转换到 ipad”。一个新的目标和一组新的 xib 被创建。它应该减少一些工作。
Hope it helps.
希望能帮助到你。
回答by antalkerekes
Xcode 4:
Xcode 4:
The Create iPad Version Using Autosizing Masksfeature has been removed from Xcode 4. Right now the easiest way is to use Xcode 3 for the conversion, since the nib (.xib) file format did not change.
在创建iPad版使用自动调整大小面具功能已在Xcode 4去除眼下最简单的方法是使用的Xcode 3的转换,因为笔尖(的.xib)文件格式并没有改变。
Xcode 3 & 4 can now be both installed on the same system by simply selecting a different folder (see installation instructions on the disk image).
Xcode 3 和 4 现在只需选择不同的文件夹即可安装在同一系统上(请参阅磁盘映像上的安装说明)。
Otherwise you will need to copy/paste the UI elements from the iPhone version, and re-link them to your code.
否则,您将需要从 iPhone 版本复制/粘贴 UI 元素,并将它们重新链接到您的代码。
回答by Guillaume
What about letting the computer do computer's job?
Faster, less risk of errors.
让计算机完成计算机的工作怎么样?
速度更快,出错风险更低。
Here is a workflow based on the excellent answer from Jag, but automated with sed.
这是一个基于Jag 优秀答案的工作流程,但使用 sed 自动化。
First, let's setup some stuff. We will only need to do this once.
In the directory that contains your XIBs, create two files with the following content:
首先,让我们设置一些东西。我们只需要这样做一次。
在包含您的 XIB 的目录中,创建两个包含以下内容的文件:
File iPhoneToiPadXIBConversion.sed
:
文件iPhoneToiPadXIBConversion.sed
:
s/com.apple.InterfaceBuilder3.CocoaTouch.XIB/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/g
s/IBCocoaTouchFramework/IBIPadFramework/g
and file iPadToiPhoneXIBConversion.sed
:
和文件iPadToiPhoneXIBConversion.sed
:
s/com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB/com.apple.InterfaceBuilder3.CocoaTouch.XIB/g
s/IBIPadFramework/IBCocoaTouchFramework/g
Setup is now finished.
To convert a XIB, enter one of the two following commands in the terminal:
设置现已完成。要转换 XIB,请在终端中输入以下两个命令之一:
iPhone to iPad conversion:
iPhone 到 iPad 的转换:
sed -f iPhoneToiPadXIBConversion.sed MyViewController~iphone.xib > MyViewController.xib
iPad to iPhone conversion:
iPad 到 iPhone 的转换:
sed -f iPadToiPhoneXIBConversion.sed MyViewController.xib > MyViewController~iphone.xib
Just for the fun, let's create two function in zsh, to make the conversion even more simple:
为了好玩,让我们在 zsh 中创建两个函数,使转换更加简单:
function convertiPadXIBToiPhone () {
newXibName=`echo "" | /usr/bin/sed "s/.xib/~iphone.xib/"`
`/usr/bin/sed -f iPadToiPhoneXIBConversion.sed "" > "$newXibName"`
echo "Did convert to $newXibName."
}
function convertiPhoneXIBToiPad () {
newXibName=`echo "" | /usr/bin/sed "s/~iphone.xib/.xib/"`
`/usr/bin/sed -f iPhoneToiPadXIBConversion.sed "" > "$newXibName"`
echo "Did convert to $newXibName."
}
After having added this to your zsh config, converting a XIB is a simple as:
已经将此添加到您的zsh配置后,转换厦门国际银行是一个简单的:
convertiPadXIBToiPhone MyViewController.xib
or
或者
convertiPhoneXIBToiPad MyViewController.xib
回答by Dan Rosenstark
Open up the XIB in XCode 4 using "view as source code."
使用“作为源代码查看”在 XCode 4 中打开 XIB。
Before
前
Back up the nib in question.
备份有问题的笔尖。
One
一
Substitute this goo
替换这个咕
<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>
for this other goo
对于这个其他粘液
<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>
Two
二
Then, for each view in the nib using the integrated IB, delete it and then hit undo.
然后,对于使用集成 IB 的笔尖中的每个视图,将其删除,然后点击撤消。
Three
三
Then shower in hot water to wipe off that disgusting feeling you might have.
然后用热水淋浴,以消除您可能有的恶心感觉。
回答by wasigh
You can open the XIB as textfile and change the UIView size:
您可以将 XIB 作为文本文件打开并更改 UIView 大小:
Right click on your XIB file in de navigator and select: "open as..." Open as source file.
在德导航右键单击您的XIB文件,选择“打开方式...”打开源文件。
Find the UIView reference and change the Frame values:
找到 UIView 参考并更改 Frame 值:
<object class="IBUIView" id="191373211">
<string key="NSFrame">{{0, 20}, {768, 1024}}</string>
回答by Hlung
In XCode 4.3.2, the easiest way for me to create iPad version of xib is duplicating that xib file and add ~ipad
suffix to the filename. And add both "myVC.xib" and "myVC~ipad.xib" into your project. Note that it is "~ipad" NOT "~iPad". Your app will use that ~ipad version automatically when run on iPad. This also works with resource files (e.g. images).
在 XCode 4.3.2 中,我创建 xib 的 iPad 版本的最简单方法是复制该 xib 文件并~ipad
为文件名添加后缀。并将“myVC.xib”和“myVC~ipad.xib”添加到您的项目中。请注意,它是“~ipad”而不是“~iPad”。在 iPad 上运行时,您的应用程序将自动使用该 ~ipad 版本。这也适用于资源文件(例如图像)。
The best reference I could find at the moment... https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html
我目前能找到的最佳参考资料... https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/ImageSoundResources/ImageSoundResources.html
回答by 0oneo
Xcode 5 update
Xcode 5 更新
targetRuntime="iOS.CocoaTouch"
targetRuntime="iOS.CocoaTouch"
to
到
targetRuntime="iOS.CocoaTouch.iPad"
targetRuntime="iOS.CocoaTouch.iPad"