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

        <tfoot id='h6z0E'></tfoot>

        <small id='h6z0E'></small><noframes id='h6z0E'>

        使用自动布局,如何根据图像使 UIImageView 的大小动态变化?

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

        <tfoot id='iRKTD'></tfoot>
          <bdo id='iRKTD'></bdo><ul id='iRKTD'></ul>
            <tbody id='iRKTD'></tbody>

              1. <small id='iRKTD'></small><noframes id='iRKTD'>

                • 本文介绍了使用自动布局,如何根据图像使 UIImageView 的大小动态变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望我的 UIImageView 根据它所显示的实际图像的大小来增长或缩小.但我希望它保持垂直居中,距离超级视图的前沿 10 点.

                  I want my UIImageView to grow or shrink depending on the size of what the actual image it's displaying is. But I want it to stay vertically centered and 10pts from the leading edge of the superview.

                  但是,如果我设置了这两个约束,它会抱怨我没有设置足够的约束来满足自动布局.对我来说,它似乎完美地描述了我想要的东西.我错过了什么?

                  However, if I set these two constraints it complains I haven't set up enough constraints to satisfy Auto Layout. To me it seems to perfectly describe what I want. What am I missing?

                  推荐答案

                  图像视图的固有大小已经取决于图像的大小.您的假设(和约束是正确的).

                  The image view's intrinsic size is already dependent on the size of the image. Your assumptions (and constraints are correct).

                  但是,如果您在界面构建器中设置了图像视图并且没有为它提供图像,那么布局系统(界面构建器)将不知道您的图像视图在编译时应该有多大.您的布局不明确,因为您的图像视图可能有多种尺寸.这就是引发错误的原因.

                  However, if you've set up your image view in interface builder and have not provided it with an image, then the layout system (interface builder) won't know how big your image view is supposed to be at compile time. Your layout is ambiguous because your image view could be many sizes. This is what throws the errors.

                  一旦您设置了图像视图的图像属性,图像视图的固有大小就由图像的大小定义.如果您在运行时设置视图,那么您可以完全按照 Anna 提到的操作,并在图像视图的属性检查器中为界面构建器提供占位符"内在大小.这告诉界面生成器,暂时使用这个尺寸,稍后我会给你一个真实的尺寸".占位符约束在运行时被忽略.

                  Once you set your image view's image property, then the image view's intrinsic size is defined by the size of the image. If you're setting the view at runtime, then you can do exactly what Anna mentioned and provide interface builder with a "placeholder" intrinsic size in the property inspector of the image view. This tells interface builder, "use this size for now, I'll give you a real size later". The placeholder constraints are ignored at runtime.

                  您的另一个选择是直接将图像分配给界面构建器中的图像视图(但我假设您的图像是动态的,所以这对您不起作用).

                  Your other option is to assign the image to the image view in interface builder directly (but I assume your images are dynamic, so this won't work for you).

                  这篇关于使用自动布局,如何根据图像使 UIImageView 的大小动态变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有隐藏 UIView 的自动布局? 下一篇:自动首选最大布局宽度在 8.0 之前的 iOS 版本中不可用

                  相关文章

                • <legend id='zPQqB'><style id='zPQqB'><dir id='zPQqB'><q id='zPQqB'></q></dir></style></legend>
                  <tfoot id='zPQqB'></tfoot>
                • <small id='zPQqB'></small><noframes id='zPQqB'>

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