我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
当前回答
只是为了好玩,在XCode 5.1和iOS 7.1上,我还需要改变“toolVersion”和“systemVersion”的值:
toolsVersion="5023" systemVersion="13A603"
如果没有这个,新的故事板文件将无法编译
其他回答
进入目标摘要,将设备更改为通用, 然后向下设置iPad版本为任何你喜欢的故事板,包括一个复制和重命名一个如果你喜欢。
谢谢大家的回答。
我遵循了上述步骤,但当我在模拟器或iPad下运行应用程序时,它只使用iPhone故事板继续运行。
由于某种原因,当我将目标设备改为Universal而不是iPhone时,Xcode (v5.0)没有更新app-Info。plist文件来包含iPad故事板,所以我必须手动添加以下条目(使用Xcode中的plist编辑器):
主故事板文件基名(iPad) ==> MainStoryboard_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()
通过阅读stackoverflow上的许多线程,我发现解决方案是-
1.复制你的iPhone-Storyboard并重命名为MainStoryboard_iPad.storyboard
2.右击故事板->“打开为”->“源代码”。
3.搜索targetRuntime="iOS "。CocoaTouch,然后把它改成targetRuntime=" ios。CocoaTouch。ipad "
5.搜索<simulatedScreenMetrics key="destination" type="retina4"/>并将其更改为<simulatedScreenMetrics key="destination"/>
4.现在保存所有内容,右键单击MainStoryboard_iPad。storyboard " open as " ->"IOS storyboard " 5. 您可能还必须更改您的约束条件。 这就是你所做的一切。
There is a really simple solution for Xcode versions that support size classes (Tested in Xcode 7 which is the current version at the time of writing). Check the "use size classes" checkbox on a storyboard file (File Inspector), confirm that dialog that appears. Then uncheck that same checkbox - Xcode will ask you if you want to use this storyboard with an iPhone or iPad, and convert the screens in it appropriately. No need to directly edit the storyboard file. For both iPad and iPhone, just copy the same storyboard and configure one for iPad and one for iPhone using the described method.
在有人建议使用大小类之前——虽然很好,但对于重度定制的UI,比如游戏等,它们不太方便