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

    1. <legend id='5wqDH'><style id='5wqDH'><dir id='5wqDH'><q id='5wqDH'></q></dir></style></legend>

        <bdo id='5wqDH'></bdo><ul id='5wqDH'></ul>

        <small id='5wqDH'></small><noframes id='5wqDH'>

        自动布局以保持视图大小成比例

        时间:2023-09-11
        <i id='oFYN6'><tr id='oFYN6'><dt id='oFYN6'><q id='oFYN6'><span id='oFYN6'><b id='oFYN6'><form id='oFYN6'><ins id='oFYN6'></ins><ul id='oFYN6'></ul><sub id='oFYN6'></sub></form><legend id='oFYN6'></legend><bdo id='oFYN6'><pre id='oFYN6'><center id='oFYN6'></center></pre></bdo></b><th id='oFYN6'></th></span></q></dt></tr></i><div id='oFYN6'><tfoot id='oFYN6'></tfoot><dl id='oFYN6'><fieldset id='oFYN6'></fieldset></dl></div>

            <tbody id='oFYN6'></tbody>
        1. <tfoot id='oFYN6'></tfoot>
        2. <small id='oFYN6'></small><noframes id='oFYN6'>

            <bdo id='oFYN6'></bdo><ul id='oFYN6'></ul>
              • <legend id='oFYN6'><style id='oFYN6'><dir id='oFYN6'><q id='oFYN6'></q></dir></style></legend>

                  本文介绍了自动布局以保持视图大小成比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在努力实现以下目标:

                  I'm trying to achieve the following:

                  • 我的 xib 中有 2 个视图需要与边缘(两侧和顶部)保持 20 像素的距离
                  • 需要调整大小的 2 个视图大小不同
                  • 它们必须相距 20 像素
                  • 它们的宽度需要保持相对于父视图的宽度

                  我阅读了一个关于这样做的教程并且它可以工作,但它的问题是它要求两个视图具有相同的宽度并且固定 Widths 相同,这是我不想要的.

                  I read a tutorial about doing just that and it works but the problem with it is that it requires both views to have the same width and pin Widths equally, which I don't want.

                  这是我尝试过的:

                  • 为左视图添加前导空间约束为 20 像素
                  • 为左视图添加顶部空间限制为 20 像素
                  • 为右视图添加顶部空间限制为 20 像素
                  • 为右视图添加拖尾空间限制为 20 像素
                  • 为两个视图添加水平间距限制为 20 像素

                  我遇到的问题是左视图没有调整大小,而右视图填充了空间以保持 20 像素的水平空间.

                  The problem I'm running into is that the left view doesn't resize and the right view fills out the space to keep the 20 pixels horizontal space.

                  有没有办法让两个视图按比例调整它们应该填充的空间?

                  Is there a way I can get both views to resize proportionally to the space they should be filling?

                  这是我的布局和约束的截图:

                  Here are the screenshots of my layout and constraints:

                  谢谢!

                  编辑

                  我在尝试旋转设备时收到以下警告:

                  I get the following warning when I try to rotate my device:

                  2012-10-11 08:59:00.435 AutolayoutTest[35672:c07] Unable to simultaneously satisfy constraints.
                      Probably at least one of the constraints in the following list is one you don't want.
                      Try this: (1) look at each constraint and try to figure out which you don't expect;
                      (2) find the code that added the unwanted constraint or constraints and fix it. (Note:  
                      If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
                  (
                      "<NSLayoutConstraint:0x8a6b2b0 H:[UIView:0x8a6b1d0(170)]>",
                      "<NSLayoutConstraint:0x8a68ad0 H:[UIView:0x8a69430(90)]>",
                      "<NSLayoutConstraint:0x8a6ba40 H:[UIView:0x8a69430]-(20)-[UIView:0x8a6b1d0]>",
                      "<NSLayoutConstraint:0x8a6ba00 H:[UIView:0x8a6b1d0]-(20)-|   (Names: '|':UIView:0x8a6b7e0 )>",
                      "<NSLayoutConstraint:0x8a6b940 H:|-(20)-[UIView:0x8a69430]   (Names: '|':UIView:0x8a6b7e0 )>",
                      "<NSAutoresizingMaskLayoutConstraint:0x7199aa0 h=--& v=--& V:[UIView:0x8a6b7e0(568)]>"
                  )
                  
                  Will attempt to recover by breaking constraint 
                  <NSLayoutConstraint:0x8a6b2b0 H:[UIView:0x8a6b1d0(170)]>
                  

                  推荐答案

                  这可以通过添加一个虚拟视图(dummyView)来解决,其约束设置为固定宽度、高度并对齐到 centerXSuperview.然后将左视图和右视图水平间距约束添加到dummyView.

                  This can be resolved by adding one more dummy view(dummyView) with its constraints set to Fixed width, height and aligned to centerX of Superview.Then add left view and right view Horizontal spacing constraint to dummyView.

                  这篇关于自动布局以保持视图大小成比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:CALayer IOS上的自动布局约束 下一篇:AutoLayout 多行 UILabel 截断一些文本

                  相关文章

                  <legend id='5DYof'><style id='5DYof'><dir id='5DYof'><q id='5DYof'></q></dir></style></legend>
                    <bdo id='5DYof'></bdo><ul id='5DYof'></ul>

                      <small id='5DYof'></small><noframes id='5DYof'>

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