1. <i id='9qmSr'><tr id='9qmSr'><dt id='9qmSr'><q id='9qmSr'><span id='9qmSr'><b id='9qmSr'><form id='9qmSr'><ins id='9qmSr'></ins><ul id='9qmSr'></ul><sub id='9qmSr'></sub></form><legend id='9qmSr'></legend><bdo id='9qmSr'><pre id='9qmSr'><center id='9qmSr'></center></pre></bdo></b><th id='9qmSr'></th></span></q></dt></tr></i><div id='9qmSr'><tfoot id='9qmSr'></tfoot><dl id='9qmSr'><fieldset id='9qmSr'></fieldset></dl></div>
      <tfoot id='9qmSr'></tfoot>

      • <bdo id='9qmSr'></bdo><ul id='9qmSr'></ul>

      <small id='9qmSr'></small><noframes id='9qmSr'>

    2. <legend id='9qmSr'><style id='9qmSr'><dir id='9qmSr'><q id='9qmSr'></q></dir></style></legend>

      我如何将一个故事板用于 4 英寸和 3.5 英寸iphone 屏幕自动布局(ios6 + ios7)?

      时间:2023-09-10
    3. <small id='raY9e'></small><noframes id='raY9e'>

        <tbody id='raY9e'></tbody>
          <bdo id='raY9e'></bdo><ul id='raY9e'></ul>

          1. <tfoot id='raY9e'></tfoot>

              • <i id='raY9e'><tr id='raY9e'><dt id='raY9e'><q id='raY9e'><span id='raY9e'><b id='raY9e'><form id='raY9e'><ins id='raY9e'></ins><ul id='raY9e'></ul><sub id='raY9e'></sub></form><legend id='raY9e'></legend><bdo id='raY9e'><pre id='raY9e'><center id='raY9e'></center></pre></bdo></b><th id='raY9e'></th></span></q></dt></tr></i><div id='raY9e'><tfoot id='raY9e'></tfoot><dl id='raY9e'><fieldset id='raY9e'></fieldset></dl></div>
                <legend id='raY9e'><style id='raY9e'><dir id='raY9e'><q id='raY9e'></q></dir></style></legend>

                本文介绍了我如何将一个故事板用于 4 英寸和 3.5 英寸iphone 屏幕自动布局(ios6 + ios7)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                虽然关于构建适用于 4" 和 3.5" 屏幕尺寸的故事板布局有很多问题和答案,但我找不到适合以下场景的解决方案.

                While there are many questions and answers about building a storyboard layout that would work both on 4" and 3.5" screen sizes, I couldn't find a suitable solution for the following scenario.

                我在 ios6(和 ios7)中使用自动布局,我不必支持 landscpae 或 ipad.我有一个带有几个子视图的 UIView,它们必须看起来像下面的模型.在故事板中设置自动布局约束以适应任何一种屏幕尺寸都很容易.我的问题是 - 如何让自动布局在运行时根据屏幕尺寸选择正确的约束?

                I use autolayout with ios6 (and ios7), and I don't have to support landscpae or ipad. I have a UIView with several subviews, which have to look as the mockup below. It is easy to set up autolayout constraints in the storyboard to fit either of the screen sizes. My question is - how do I make autolayout choose the correct constraints depending on the screen size at runtime?

                请注意,我不想使用 2 个不同的故事板.在我的整个应用程序中这样做需要做很多工作,而且我必须连接每个故事板上的所有代表、出口和动作.换一个屏幕需要我做双倍的工作.

                Note, that I DONT want to use 2 different storyboards. Doing so across my whole application would be a lot of work, and I would have to hook up all the delegates, outlets and actions on each storyboard. A change in a screen would require me to do double the work.

                我尝试了 2 种方法来在一个情节提要上完成这项工作,但我对其中任何一种都不满意.

                I have tried 2 methods to make this work on one storyboard, but I'm not satisfied with either of them.

                • 双重约束.较大的约束 (50) 具有比较低的约束 (30) 更高的优先级.这种方法的问题在于,在 3.5 英寸的屏幕尺寸上,自动布局可能会选择一些较低优先级的约束——足以满足布局——但会留下一些高优先级的约束.

                • 子类 NSLayoutConstraint.在这个方法中,storyboard 中的所有约束都设置为 NSDualLayoutConstraint.在 NSDualLayoutConstraint 的初始化代码中,将约束的常量更改为 3_5_constant 的值,以防运行时屏幕大小为 3.5".这种方法更具确定性,但在界面生成器预览中看不到 3.5" 布局.

                如果只有界面构建器约束有一个辅助常量值,当屏幕尺寸为 3.5" 时将应用它,它会解决我的问题..所以我的问题仍然存在 - 如何正确使用单个故事板为 4" 和 3.5" 屏幕尺寸正确布局其子视图?

                If only interface builder constraints had a secondary constant value that would be applied when the screen size is 3.5", it would solve my problem.. So I remain with my question - how can I properly use a single storyboard to layout its subviews correctly for 4" AND 3.5" screen sizes?

                推荐答案

                如果您只想使用一个故事板并且不想使用自动布局,这将使您的生活更轻松你的图表,你将不得不在代码中布局你的视图.

                If you want to use only one storyboard and you do not want to utilize auto layout, which would make your life a lot easier for what you've shown in your diagram, you will have to layout your views in code.

                您只需要检测用户是否在 4" 设备上运行并相应地布局您的视图.

                You will just need to detect if the user is running on a 4" device and layout your views accordingly.

                #define IS_568_SCREEN (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
                
                if (IS_568_SCREEN) {
                    // Lots of code to layout for 4" devices
                } else {
                    // Lots of code to layout for 3.5" devices
                }
                

                但是,如果您为此使用自动布局,您会发现它会为您节省大量时间和代码.不必使用我上面提到的解决方案在代码中手动布局每个视图,您只需根据设备更新 y 和高度约束.

                However, if you were to use autolayout for this, you'd find it's going to save you a ton of time and code. Instead of having to manually layout every view in code using the solution I mentioned above, you'd simply need to update the y and height constraints depending on the device.

                考虑到这个图表显示了自动布局将为您处理什么以及您需要手动更新什么,这应该有助于更好地了解使用自动布局可以节省多少.

                Considering this diagram showing what autolayout would handle for you and what you'd need to update manually, this should help paint a better picture of just how much you'll save with utilizing autolayout.

                #define IS_568_SCREEN (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
                
                if (IS_568_SCREEN) {
                    self.layoutConstraintY.constant = 50.0f;
                    self.layoutConstraintHeight.constant = 248.0f;
                } else {
                    self.layoutConstraintY.constant = 30.0f;
                    self.layoutConstraintHeight.constant = 220.0f;
                }
                [self layoutIfNeeded];
                

                这篇关于我如何将一个故事板用于 4 英寸和 3.5 英寸iphone 屏幕自动布局(ios6 + ios7)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:具有自动布局约束的 UIView 动画更改 下一篇:匹配自定义 &amp; 的左对齐标准 UITableViewCell 类型

                相关文章

              • <small id='Amnlv'></small><noframes id='Amnlv'>

                <legend id='Amnlv'><style id='Amnlv'><dir id='Amnlv'><q id='Amnlv'></q></dir></style></legend>
                  <tfoot id='Amnlv'></tfoot>

                1. <i id='Amnlv'><tr id='Amnlv'><dt id='Amnlv'><q id='Amnlv'><span id='Amnlv'><b id='Amnlv'><form id='Amnlv'><ins id='Amnlv'></ins><ul id='Amnlv'></ul><sub id='Amnlv'></sub></form><legend id='Amnlv'></legend><bdo id='Amnlv'><pre id='Amnlv'><center id='Amnlv'></center></pre></bdo></b><th id='Amnlv'></th></span></q></dt></tr></i><div id='Amnlv'><tfoot id='Amnlv'></tfoot><dl id='Amnlv'><fieldset id='Amnlv'></fieldset></dl></div>
                    <bdo id='Amnlv'></bdo><ul id='Amnlv'></ul>