我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
我有一个iPhone应用程序,它有一个故事板。现在我还想提供一个iPad应用程序。我问自己是否有一个函数可以帮助我将iPhone的故事板转换成iPad的故事板。
具体来说:
是否有类似的功能,还是只有手动的方式?
当前回答
如果你创建了一个通用项目,默认情况下会创建空的iPad storyboard,你只需要选择iPhone storyboard select all (Command+ a),复制(Command+C),然后粘贴到iPad storyboard上。在编译之前,请确保将入口点从空故事板移动到新复制的故事板。
其他回答
这个功能现在是内置的。例如,如果将“部署信息->设备”中的项目设置从iPhone更改为Universal,则会出现以下对话框:
使用XCode6大小类,您不再需要将故事板转换为iPad。 同一个Storyboard可以同时用于iPhone和iPad,使您不必同时更新两个文件。
生成的故事板与iOS7+兼容。
点击这里阅读更多信息: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html#//apple_ref/doc/uid/TP40014436-CH6-SW1
使用大小类使故事板或xib文件能够处理所有可用的屏幕大小。这使得应用程序的用户界面可以在任何iOS设备上工作。
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,比如游戏等,它们不太方便
不同的方法
在iPad-Storyboard中添加一个带有Navigation-Controller的empty-View-Controller 将类更改为你的第一个用于iPhone的ViewController的类"fooViewController" 为第一个ViewController添加iPhone-Storyboard "fooViewController_storyboard_identifier"中的Storyboard-Identifier 转到fooviewcontroller。m 添加bool变量bool nibWasLoadForIpad=false 进入viewDidLoad-Method
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && !nibWasLoadForIpad) { nibWasLoadForIpad = true; UIStoryboard* Storyboard_iphone=[UIStoryboard storyboardWithName:@"Main_iPhone" bundle: nil]; fooViewController *controller = [Storyboard_iphone instantiateViewControllerWithIdentifier:@"fooViewController_storyboard_identifier"]; (自我。导航控制器pushViewController:控制器动画:YES]; 自我。modalPresentationStyle = UIModalPresentationCurrentContext; }
(ps.知道的问题是视图背景将被设置为白色)
我找到了一种解决方案:
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.
这节省了我很多时间,希望这对你们有帮助