ios 将故事板从 iPhone 转换为 iPad

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8465769/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:49:54  来源:igfitidea点击:

Converting Storyboard from iPhone to iPad

iosiphonexcodeipadstoryboard

提问by dehlen

I have an iPhoneapplication which has a storyboard. Now I want to provide an iPadapplication too. So I asked me whether there is a function which helps me convert my iPhonestoryboard to an iPadstoryboard.

我有一个iPhone带有故事板的应用程序。现在我也想提供一个iPad应用程序。所以我问我是否有一个功能可以帮助我将iPhone故事板转换为iPad故事板。

To be specific:

再具体一点:

Is there a similar function or is there only the manual way ?

有类似的功能还是只有手动方式?

回答by tharkay

I found out a kind of solution:

我找到了一种解决方案:

  1. Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard

  2. Close Xcode and then open this file any text editor.

  3. Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"

  4. Change the code in the MainStoryboard_iPad.storyboard from:

    <simulatedScreenMetrics key="destination" type="retina4"/>to

    <simulatedScreenMetrics key="destination"/>

  5. Now save everything and reopen Xcode. The iPad-Storyboard has the same contents as the iPhone-file but everyting could be disarranged.

  1. 复制你的 iPhone 故事板并重命名 MainStoryboard_iPad.storyboard

  2. 关闭 Xcode,然后在任何文本编辑器中打开此文件。

  3. 搜索targetRuntime="iOS.CocoaTouch"并将其更改为targetRuntime="iOS.CocoaTouch.iPad"

  4. 将 MainStoryboard_iPad.storyboard 中的代码更改为:

    <simulatedScreenMetrics key="destination" type="retina4"/>

    <simulatedScreenMetrics key="destination"/>

  5. 现在保存所有内容并重新打开 Xcode。iPad-Storyboard 与 iPhone 文件具有相同的内容,但一切都可能被打乱。

This saved me hours - hopefully this will help you

这节省了我几个小时 - 希望这会帮助你

回答by Malls

If you had created a universal project, by default empty iPad storyboard would have been created, you just have to select iPhone storyboard select all (Command+A), copy (Command+C) and paste it on iPad storyboard. Make sure to move the entry point from the empty storyboard to newly copied storyboard before compiling.

如果您创建了一个通用项目,默认情况下会创建空的 iPad 故事板,您只需选择 iPhone 故事板全选 (Command+A),复制 (Command+C) 并将其粘贴到 iPad 故事板。确保在编译之前将入口点从空的故事板移动到新复制的故事板。

回答by Nelson Brian

That didn't quite work for me. I did something a little bit different.

那对我来说不太奏效。我做了一些不同的事情。

  1. Create a new story board file for the iPad version
  2. Open both the new file and the file i want to copy in textwrangler (text editor)
  3. Copied the xml text from old file to the new file between these xml tags
  4. First Tag <scenes> <!--Contents View Controller-->
  5. Paste Here
  6. End Tags </class> </classes>
  1. 为 iPad 版本创建一个新的故事板文件
  2. 在 textwrangler(文本编辑器)中打开新文件和我想复制的文件
  3. 将旧文件中的 xml 文本复制到这些 xml 标记之间的新文件中
  4. 第一个标签 <scenes> <!--Contents View Controller-->
  5. 粘贴在这里
  6. 结束标签 </class> </classes>

That worked for me. I got a new layoutout with all my outlets connected, which alone saved me a few hours.

那对我有用。我得到了一个新的布局,连接了我所有的插座,仅此一项就为我节省了几个小时。

回答by Kirit Vaghela

1. Create New Storyboard file with MainStoryboard_iPad.storyboard
2. Copy All the views from MainStoryboard and paste to MainStoryboard_iPad.storyboard

回答by Ricardo Anjos

1 - Create your "MainStoryboard_iPad.storyboard";

1 - 创建你的 "MainStoryboard_iPad.storyboard";

2 - Right-click on you "MainStoryboard_iPhone.storyboard"and "Open as -> Source Code". Copy everything;

2 - 右键单击​​您"MainStoryboard_iPhone.storyboard"并“打开为 -> 源代码”。复制一切;

3- Right-click on you "MainStoryboard_iPad.storyboard"and "Open as -> Source Code". Paste everything. Now Search and change:

3- 右键单击​​您"MainStoryboard_iPad.storyboard"并“打开为 -> 源代码”。粘贴一切。现在搜索并更改:

  • targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
  • type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" to type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.iPad.XIB"
  • targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
  • type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" to type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.iPad.XIB"

4 - Save. Now reopen but using the interface builder. You will only have to re-arrange.

4 - 保存。现在重新打开但使用界面构建器。你只需要重新安排。

This method can be used for .xib files too

此方法也可用于 .xib 文件

回答by Bharat

From reading many threads on stackoverflow i discovered the solution is-

通过阅读stackoverflow上的许多线程,我发现解决方案是-

1.Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard

1.复制你的 iPhone-Storyboard 并将其重命名为 MainStoryboard_iPad.storyboard

2.right click on the storyboard -> “open as” -> “Source Code”.

2.在storyboard上右击->“打开为”->“源代码”。

3.Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"

3.搜索 targetRuntime="iOS.CocoaTouch" 并将其更改为 targetRuntime="iOS.CocoaTouch.iPad"

5.Search for <simulatedScreenMetrics key="destination" type="retina4"/>and change it to to <simulatedScreenMetrics key="destination"/>

5.搜索<simulatedScreenMetrics key="destination" type="retina4"/>并更改为<simulatedScreenMetrics key="destination"/>

4.Now save everything and right click on MainStoryboard_iPad.storyboard “open as” ->"IOS StoryBoard" 5. you may also have to change your constraints. Thats all you have done.

4.现在保存所有内容并右键单击 MainStoryboard_iPad.storyboard “open as” ->“IOS StoryBoard” 5. 您可能还需要更改约束。这就是你所做的一切。

回答by Symmetric

This is going the other way, but I was able to do a select all & copy in my iPad storyboard (~35 scenes) and paste it into my iPhone storyboard. The scene sizes were automatically adjusted. I only saw two problems, I had to replace UISplitViewController (since it's only iPad), and the default background became transparent instead of gray (still working on fixing that properly, without manually setting the background for everything).

这是相反的,但我能够在我的 iPad 故事板(约 35 个场景)中进行全选并复制并将其粘贴到我的 iPhone 故事板中。场景大小自动调整。我只看到两个问题,我不得不替换 UISplitViewController(因为它只是 iPad),并且默认背景变为透明而不是灰色(仍在努力修复该问题,无需手动为所有内容设置背景)。

EDIT: It seems the default background for UITableView in the Attributes inspector is rather strange. I had to manually set the background to "Group Table View Background Color" for grouped table views, and "White Color" for non-grouped table views. It then was displayed as "Default" (I assume since it then matched a hardcoded value). -- Actually, even easier, changing from "Grouped" to "Static" and back seems to reset the default color.

编辑:属性检查器中 UITableView 的默认背景似乎很奇怪。我必须手动将背景设置为分组表视图的“分组表视图背景颜色”,以及非分组表视图的“白色”。然后它被显示为“默认”(我假设因为它然后匹配了一个硬编码值)。-- 实际上,更简单的是,从“分组”更改为“静态”并返回似乎重置了默认颜色。

回答by Chris Robertson

Here's something that saved me hours and might help those of you with Python skills.

这里有一些东西可以节省我几个小时,并且可能会帮助那些掌握 Python 技能的人。

I've been building an app for the last two months, focused on just iPad iterating the UX with the team.

在过去的两个月里,我一直在构建一个应用程序,专注于 iPad 与团队一起迭代用户体验。

Today focused on building out iPhone version, followed the steps above (thanks!) but I didn't want to then have to resize all the ui elements from iPad dimensions in the visual storyboard editor.

今天专注于构建 iPhone 版本,遵循上述步骤(谢谢!)但我不想在视觉故事板编辑器中调整 iPad 尺寸中所有 ui 元素的大小。

So I wrote this little python jig script to scan through the storyboard file for x, y, width, height and scale everything down by by ratio 320./768. Allowed me then to just focus on fine adjustments.

所以我写了这个小的 python jig 脚本来扫描故事板文件的 x、y、宽度、高度并将所有内容按比例缩小 320./768。然后让我只专注于微调。

  1. Copy your iPad storyboard into a new file. (e.g. iPhoneStoryboard.storyboard)

  2. Run the script below with the copied storyboard filename as the first parameter.

  3. Will generate output file with suffix _adjusted.storyboard (e.g. iPhoneStoryboard.storyboard_adjusted.storyboard)

  1. 将您的 iPad 故事板复制到一个新文件中。(例如 iPhoneStoryboard.storyboard)

  2. 使用复制的故事板文件名作为第一个参数运行下面的脚本。

  3. 将生成后缀为 _adjusted.storyboard 的输出文件(例如 iPhoneStoryboard.storyboard_adjusted.storyboard)

Hope it helps...

希望能帮助到你...

import re
import sys
import math

afile = sys.argv[1]

scale = 320./768.

number_pattern = '[-0-9]+(.[0-9]+)?'
#width_pattern = 'width="[-0-9]+( ?px)?"'
width_pattern = 'width="[-0-9]+(.[0-9]+)?( ?px)?"'
height_pattern = 'height="[-0-9]+(.[0-9]+)?( ?px)?"'
x_pattern = 'x="[-0-9]+(.[0-9]+)?( ?px)?"'
y_pattern = 'y="[-0-9]+(.[0-9]+)?( ?px)?"'


def replacescaledvalue(scale,pattern,sometext,replacefmt) :
    ip = re.search(pattern, sometext, re.IGNORECASE)
    if(ip) :
        np = re.search(number_pattern,ip.group(0))
        if(np) :
            val = float(np.group(0))
            val = int(math.floor(val*scale))
            sval = replacefmt+str(val)+'"'#+'px"'
            newtext = re.sub(pattern,sval,sometext)
            return newtext
    else :
        return sometext

fin = open(afile)
fout = open(afile+"_adjusted.storyboard", "wt")
for line in fin:
    newline = line
    newline = replacescaledvalue(scale,width_pattern,newline,'width="')
    newline = replacescaledvalue(scale,height_pattern,newline, 'height="')
    newline = replacescaledvalue(scale,x_pattern,newline, 'x="')
    newline = replacescaledvalue(scale,y_pattern,newline, 'y="')
#   print newline
    fout.write( newline )

fin.close()
fout.close()

回答by TooManyEduardos

Just for fun, on XCode 5.1 and iOS 7.1 I also needed to change the values of "toolVersion" and "systemVersion" to this:

只是为了好玩,在 XCode 5.1 和 iOS 7.1 上,我还需要将“toolVersion”和“systemVersion”的值更改为:

toolsVersion="5023" systemVersion="13A603"

Without this, the new storyboard file wouldn't compile

没有这个,新的故事板文件将无法编译

回答by dgetzin

Just as a quick gotcha note to those who may have had my issue with this:

就像对那些可能遇到我的问题的人的快速提示一样:

My issue:

我的问题:

The storyboard content copied over nicely to a new board file I added. However, it would not put changes over to my provisioned iPad. Noticing that I had to switch over the designated storyboard for the build target (see image) let the changes show.

故事板内容很好地复制到我添加的新板文件中。但是,它不会对我配置的 iPad 进行更改。注意到我必须为构建目标切换指定的故事板(见图)让更改显示出来。

I'd post an image if I had the points, but the setting is located in:

如果我有积分,我会发布一张图片,但设置位于:

Project navigator on the left side source menu, root target of project (center pane) general tab, (second subhead) deployment info, with the iPad button tab selected.

左侧源菜单上的项目导航器、项目的根目标(中心窗格)常规选项卡、(第二个副标题)部署信息,选择 iPad 按钮选项卡。

From there, choose your storyboard under "main interface."

从那里,在“主界面”下选择您的故事板。

Thanks for the post, I hope this mention helps a snag somewhere.

感谢您的帖子,我希望这个提及有助于某个地方的障碍。