我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
当前回答
这里有一些为我节省了时间的东西,可能会对那些掌握Python技能的人有所帮助。
在过去的两个月里,我一直在开发一款应用,专注于与团队一起在iPad上迭代用户体验。
今天的重点是构建iPhone版本,遵循上面的步骤(谢谢!),但我不想在视觉故事板编辑器中从iPad尺寸调整所有ui元素的大小。
所以我写了这个python jig脚本来扫描故事板文件的x y宽度和高度并将所有内容按320 /768的比例缩小。让我能够专注于精细的调整。
复制你的iPad故事板到一个新文件。(如iPhoneStoryboard.storyboard) 运行下面的脚本,将复制的故事板文件名作为第一个参数。 将生成后缀为_adjusted的输出文件。storyboard(例如iPhoneStoryboard.storyboard_adjusted.storyboard)
希望能有所帮助……
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()
其他回答
这是另一种方式,但我能够做一个全选&复制在我的iPad故事板(~35个场景),并粘贴到我的iPhone故事板。场景大小自动调整。我只看到了两个问题,我必须替换UISplitViewController(因为它只是iPad),默认背景变成透明而不是灰色(仍在正确地修复这个问题,无需手动设置所有背景)。
编辑:在属性检查器中UITableView的默认背景似乎很奇怪。对于分组的表视图,我必须手动设置背景为“组表视图背景色”,对于非分组的表视图,我必须手动设置背景为“白色”。然后它被显示为“Default”(我假设它匹配了一个硬编码的值)。实际上,更简单的是,从“分组”切换到“静态”,然后再切换回来似乎会重置默认颜色。
1. Create New Storyboard file with MainStoryboard_iPad.storyboard
2. Copy All the views from MainStoryboard and paste to MainStoryboard_iPad.storyboard
当我昨天遇到同样的问题时,我关注了这个帖子。我遵循的步骤
For Xcode 5.1, I had to do some cleanup of iPhone storyboard like missing reuseIdentifiers of Table cells, provide story board id for every controller, remove unused scenes. Copy MainStoryboard_iPhone.storyboard to MainStoryboard_iPad.storyboard. Using vi editor - changed targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad" Change the code in the MainStoryboard_iPad.storyboard from: <simulatedScreenMetrics key="destination" type="retina4"/> to <simulatedScreenMetrics key="destination"/> Open the project in Xcode. Changed the Deployment devices to Universal - Chose the option of NOT copying the iPhone Storyboard. Xcode will default the Deployment Target to 7.1, took care of the deprecated functions. To fix the misplaced view error in iPad Storyboard - Changed the Frame Layout for Controllers giving errors.
就是这样。谢谢你的帮助。
这个功能现在是内置的。例如,如果将“部署信息->设备”中的项目设置从iPhone更改为Universal,则会出现以下对话框:
我找到了一种解决方案:
Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard Close Xcode and then open this file any text editor. Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad" Change the code in the MainStoryboard_iPad.storyboard from: <simulatedScreenMetrics key="destination" type="retina4"/> to <simulatedScreenMetrics key="destination"/> Now save everything and reopen Xcode. The iPad-Storyboard has the same contents as the iPhone-file but everyting could be disarranged.
这节省了我很多时间,希望这对你们有帮助