简体   繁体   English

如何为iPhone 6 Plus上的所有iPhone设备支持一个xib?

[英]How to support one xib for all iPhone devices upto iPhone 6 Plus?

I started one new iOS apllication. 我开始了一个新的iOS应用程序。 And that application requirement is app should support from iPhone 4 to iPhone 6 Plus. 应用程序要求应用程序应支持从iPhone 4到iPhone 6 Plus。 I am very much familiar with using Xib files. 我非常熟悉使用Xib文件。 So far I differentiated my apps with iPhone 5 and below iPhone 5. For that I Used 2 Xib files for one is for iPhone 5 and other is iPhone 5 below according to device height I added like that. 到目前为止,我将我的应用程序与iPhone 5和iPhone 5以下区分开来。为此,我使用2个Xib文件,一个用于iPhone 5,另一个是iPhone 5,根据设备高度,我添加了这样。 But now apple has relased iPhone 6 and iPhone 6 Plus with iOS 8 along with XCode 6. For these 4 types devices, 但是现在苹果已经将iPhone 6和iPhone 6 Plus与iOS 8以及XCode 6相关联。对于这4种类型的设备,

1) iPhone 4 2) iPhone 5 3) iPhone 6 and 4) iPhone 6 Plus do I need to add 4 Xibs or any other solution . 1)iPhone 4 2)iPhone 5 3)iPhone 6和4)iPhone 6 Plus我需要添加4个Xib或任何其他解决方案

To learn Storyboards, now I don't have that much time because my app has already release date confirmed from Client. 要学习故事板,现在我没有那么多时间,因为我的应用程序已经从客户端确认了发布日期。 But I will learn about sotryboard in future definately. 但我将来肯定会了解sotryboard。

I have tried with Autolayout concept, but its not worked for me. 我尝试过使用Autolayout概念,但它对我不起作用。 and I dont have full awarness on Autolayout concept also. 而且我对Autolayout概念也没有充分的了解。 Yesterday I started my new project with XCode 6, So I taken iPhone 6 view and tried to use autoresizing and autolayout but not worked for me and views are overlapping. 昨天我用XCode 6开始了我的新项目,所以我采用了iPhone 6视图并尝试使用自动调整和自动布局但不适用于我并且视图重叠。 I know for different devices creating different xibs is not good practice. 我知道不同的设备创建不同的xib并不是一个好习惯。 For creating each device with each xib would take huge time. 使用每个xib创建每个设备将花费大量时间。 I am really bothering about this how to handle different devices from yesterday onwards. 从昨天开始,我真的很烦心如何处理不同的设备。 Please somebody help me to came out from this issue. 请有人帮我解决这个问题。 Really highly thankful to you. 非常感谢你。 If anything mistakes in my content please forgive me. 如果我的内容有任何错误,请原谅我。

Your question deserves a longer answer than StackOverflow can provide, but there are a few pointers I can give you. 您的问题应该比StackOverflow提供的答案更长,但我可以给您一些指示。

  1. For each of your xibs, enable Size Classes and Autolayout. 对于每个xib,启用Size Classes和Autolayout。
  2. Set each xib root view's size class to width Any and height Any, which I believe are the defaults. 将每个xib根视图的大小类设置为宽度Any和height Any,我相信它是默认值。
  3. Design your interface in a way that looks decent on this theoretical Any x Any device. 在这个理论上的Any x Any设备上以一种看起来不错的方式设计你的界面。
  4. I highly recommend using a UIScrollView at the top level of any view controller's view hierarchy. 强烈建议在任何视图控制器的视图层次结构的顶层使用UIScrollView
  5. Use constraints to anchor the controls. 使用约束来锚定控件。 I find it easiest to start with the control in the top left corner, anchor it to the containing view's top and left sides, and then work your way down and across until all of your controls are constrained on all 4 sides, or on one vertical and one horizontal size, along with explicit height and width. 我发现最简单的方法是从左上角的控件开始,将其固定到包含视图的顶部和左侧,然后向下并向下工作直到所有控件都限制在所有4个边上,或者在一个垂直边上和一个水平尺寸,以及明确的高度和宽度。 Be generous with the greater-than and less-than relationships in your constraints. 对约束中的大于和小于关系慷慨。
  6. To customize for each device layout, switch the size class to the desired combination. 要自定义每个设备布局,请将尺寸类别切换为所需的组合。 Note that any constraints you add, change, or remove, as well as any controls that you add or remove, will be changed only for the current class size. 请注意,您添加,更改或删除的任何约束以及您添加或删除的任何控件都将仅针对当前类大小进行更改。 Do this for each different size class that you're going to support. 为您要支持的每个不同大小的类执行此操作。 See Apple's reference for which size classes are used for each device. 请参阅Apple的参考资料 ,了解每种设备使用的尺寸等级。
  7. Test your layouts using the Resizable Device simulators. 使用Resizable Device模拟器测试您的布局。

This is hard work, but it sure beats having to maintain a different xib for each device size. 这是一项艰苦的工作,但它必须为每种设备尺寸维护不同的xib。

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

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