<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 的大小动态变化?

        With Auto Layout, how do I make a UIImageView#39;s size dynamic depending on the image?(使用自动布局,如何根据图像使 UIImageView 的大小动态变化?)
        <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 的大小动态变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                  • <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'>

                        <tbody id='zPQqB'></tbody>
                        <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>