简体   繁体   English

环球故事板?

[英]Universal Storyboard?

In the old XIB world of iOS development, I was able to create one View Controller and one XIB, and use them for both the iPhone and iPad environments. 在iOS开发的旧XIB世界中,我能够创建一个View Controller和一个XIB,并将它们用于iPhone和iPad环境。 With just a few code tweaks, the XIB would resize and adjust to fit the different dimensions and aspect ratios. 只需进行一些代码调整,XIB就会调整大小并进行调整以适应不同的尺寸和宽高比。 This allowed me to reduce the risk of the two layouts getting out of sync over time. 这使我可以降低两种布局随时间不同步的风险。

Is the same thing possible in the world of Storyboards? 在故事板的世界中,同样的事情是可能的吗? By default Xcode creates two distinct storyboards for my Universal app -- one for the iPhone and one for the iPad. 默认情况下,Xcode为我的Universal应用程序创建了两个不同的故事板 - 一个用于iPhone,另一个用于iPad。

How can I use one storyboard for both? 如何为两者使用一个故事板?

Thanks! 谢谢!

Updated: 更新:

Size Classes in Xcode 6 will essentially achieve the goal of Universal Storyboards. Xcode 6中的大小类基本上可以实现Universal Storyboards的目标。 More info here: 更多信息:

https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html https://developer.apple.com/library/prerelease/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_6_0.html

In short...you can't. 简而言之......你做不到。

There's a workaroud I use to create the iPad storyboard at the end of the iPhone development. 在iPhone开发结束时,我用它来创建iPad故事板。

You have to locate the iPhone story board and using the Terminal you can duplicate it giving it the name of the iPad storyboard that Xcode has created for you. 您必须找到iPhone故事板并使用终端,您可以复制它,为其提供Xcode为您创建的iPad故事板的名称。 Delete the empty old storyboard and open the newly copied one changinge the targetRuntime attribute to "iOS.CocoaTouch.iPad" instead of the old value "iOS.CocoaTouch". 删除空的旧故事板并打开新复制的一个changinge targetRuntime属性为“iOS.CocoaTouch.iPad”而不是旧值“iOS.CocoaTouch”。

Open the iPad storyboard with Xcode, everything is there but it still needs to be arranged and connected to the ViewController (wiring stuff included..). 用Xcode打开iPad故事板,一切都在那里,但它仍然需要安排并连接到ViewController(包括接线的东西......)。 It's not perfect but I usually do it to save some error prone copy and paste (and several hours as well). 它并不完美,但我通常这样做是为了节省一些容易出错的复制和粘贴(以及几个小时)。

If you just want to target your app for iPhone and deliver it to iPad you can just use the iPhone Xib and you'll get the 2x little botton in your right corner. 如果您只想将iPhone的应用程序作为目标并将其发送到iPad,您只需使用iPhone Xib,就可以获得右下角的2x小按钮。

Update late 2014 (after Xcode 6 beta release) 2014年末更新(Xcode 6测试版发布后)

Xcode 6 now allows you to define a single storyboard and through the size classes concept , to make it adapt to all their devices. Xcode 6现在允许您定义单个故事板并通过大小类概念 ,使其适应所有设备。 This solution is a bit confusing (especially if you're familiar with how this problem is solved in the Android environment) but it's something in the right direction IMHO. 这个解决方案有点令人困惑(特别是如果你熟悉Android环境中如何解决这个问题),但这是正确的方向恕我直言。

Yes you can. 是的你可以。 You can simply select the very same storyboard in Xcode under General/Deployment info 您只需在常规/部署信息下的Xcode中选择相同的故事板即可

I have a few app which have that. 我有一些应用程序有这个。 They share a lot of view controllers. 他们共享很多视图控制器。 If you use freeform size than you can create separate view controller in the story board and two separate segues. 如果使用自由形式大小,则可以在故事板和两个单独的segue中创建单独的视图控制器。

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       [self performSegueWithIdentifier:@"Open VC" sender:sender];
} else {
       [self performSegueWithIdentifier:@"Open VC iPad" sender:sender];
}

Only disadvantage is that you cannot use iPad specific controls directly from the storyboard (popover etc.) unless you switch to an iPad storyboard 唯一的缺点是,除非您切换到iPad故事板,否则不能直接从故事板(popover等)使用iPad特定控件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM