简体   繁体   English

我可以在通用应用程序中制作一个可以在iPhone和iPad UI上共享的XIB / NIB吗?

[英]Can I make one XIB/NIB that can be shared across iPhone and iPad UIs in a Universal App?

Are XIBs usable across platforms? XIB是否可以跨平台使用?

EG: I'm creating a Universal app. EG:我正在创建通用应用。 When creating a new XIB, Xcode wants me to pick a device family. 创建新的XIB时,Xcode希望我选择一个设备系列。

This bit of UI will be used in both versions of the app as-is and device family isn't really relevant (it's 200x250 pixels and can be displayed on both screens). 这部分用户界面将按原样在两个版本的应用程序中使用,并且设备系列并不真正相关(它为200x250像素,可以在两个屏幕上显示)。

If I pick iPad for the device family, does this mean the xib will be invisible to the app when running on the iPhone? 如果我为设备系列选择iPad,这是否意味着xib在iPhone上运行时对应用程序不可见?

If not are there any gotchas I should be aware of? 如果没有,我应该知道的任何陷阱?

Edit: Specifically in this answer they imply that the device family is embedded in the NIB itself, possibly making it invisible on the "wrong" platform: https://stackoverflow.com/a/10459556/1461211 编辑:特别是在此答案中,它们暗示设备系列已嵌入NIB本身,可能使其在“错误”平台上不可见: https : //stackoverflow.com/a/10459556/1461211

yep they are are. 是的,他们是。 But, the layout might be tricker when laying a single XIB for both phone and iPad. 但是,当为手机和iPad放置一个XIB时,布局可能会更复杂。

If you are using iOS6+, use auto layout to create fully dynamic layouts that will work for both iPhone and iPad. 如果您使用的是iOS6 +,请使用自动布局来创建完全动态的布局,该布局将同时适用于iPhone和iPad。

For layouts that just does not look right, you can create a ~iPad version of the XIB. 对于看起来不正确的布局,可以创建XiPad的〜iPad版本。 So the iphone XIB is called 'DeskNoteDetails.xib' the iPad version would be named DeskNoteDetails~IPAD.xib' Now you can have to completely different layouts for the device. 因此,iphone XIB被称为“ DeskNoteDetails.xib”,而iPad版本将被命名为DeskNoteDetails〜IPAD.xib。现在,您必须为设备设置完全不同的布局。 When the app needs to the load the DeskNoteDetailViewController view, the framework will determine which it should load the regular XIB or the ~IPAD. 当应用程序需要加载DeskNoteDetailViewController视图时,框架将确定应加载常规XIB或〜IPAD。

So if you only have 1 XIB, the app will always load that 1 XIB for both devices. 因此,如果您只有1个XIB,则该应用将始终为两个设备加载该1个XIB。 If you have a ~IPAD xib, the app will load the correct XIB for the device. 如果您有〜IPAD xib,则应用程序将为设备加载正确的XIB。

I have a possible answer, from the Resource Programming Guide (I swear I looked in the docs before posting the question!) 我有一个可能的答案,来自《资源编程指南》(我发誓在发布问题之前先看过文档!)

"On an iPhone or iPod touch device, the system loads the MyImage~iphone.png resource file, while on iPad, it loads the MyImage~ipad.png resource file. If a device-specific version of a resource is not found, the system falls back to looking for a resource with the original filename, which in the preceding example would be an image named MyImage.png." “在iPhone或iPod touch设备上,系统会加载MyImage〜iphone.png资源文件,而在iPad上,它将加载MyImage〜ipad.png资源文件。如果找不到特定于设备的资源版本,则系统退回去寻找具有原始文件名的资源,在前面的示例中,该文件名将是名为MyImage.png的图像。”

Thus, it appears , that if there is no file with device specific extension in the file name it will load the same version on both platforms. 因此, 看来 ,如果在文件名中没有带有设备特定扩展名的文件,它将在两个平台上加载相同的版本。

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

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