• <tfoot id='M5KdE'></tfoot>
    <legend id='M5KdE'><style id='M5KdE'><dir id='M5KdE'><q id='M5KdE'></q></dir></style></legend>

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

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

        iOS 6 中具有自动布局的动态 UIView 高度

        Dynamic UIView height with auto layout in iOS 6(iOS 6 中具有自动布局的动态 UIView 高度)

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

        1. <legend id='a3RiI'><style id='a3RiI'><dir id='a3RiI'><q id='a3RiI'></q></dir></style></legend>
              <bdo id='a3RiI'></bdo><ul id='a3RiI'></ul>

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

                  本文介绍了iOS 6 中具有自动布局的动态 UIView 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在过去的几天里,我试图使用自动布局约束来完成一个相当简单(至少应该如此)的布局,但没有成功.

                  For the last couple of days I am trying to accomplish a fairly simple (at least it should be) layout using auto layout constraints, but without success.

                  我的视图层次结构是:
                  UIScrollView
                  -- UIView(容器视图)
                  -----UILabel(多行标签)
                  -----UIWebView
                  -----UILabel
                  -----UI按钮

                  My view hierarchy is:
                  UIScrollView
                  -- UIView (Container view)
                  -----UILabel (Multirow label)
                  -----UIWebView
                  -----UILabel
                  -----UIButton

                  所需的功能是根据内容的大小扩展容器视图.为了增加 UIWebView 的高度,我使用以下代码:

                  The desired functionallity is the Container view to be expanding according to the size of the contents. In order to increase the height of the UIWebView I use the following code:

                  - (void)webViewDidFinishLoad:(UIWebView *)webView {
                      [self.webView sizeToFit];
                  } 
                  

                  我尝试了许多不同的限制条件,其中最合理的限制条件是:
                  1. 将超级视图的顶部空间固定为第一个标签(事件标题)
                  2. 固定第一个标签和 UIWebView 的垂直间距
                  3. 为其余元素固定垂直间距(即 UIWebView - UILabel (Event Date) 和 UILabel (Event Date) - UIButton)
                  4.容器视图优先级低(1)底部垂直空间约束与其父视图

                  I tried many different constraints, with the most reasonable ones being:
                  1. Pin top space from superview for the 1st label (Event Title)
                  2. Pin vertical spacing for the 1st label and the UIWebView
                  3. Pin vertical spacing for the rest elements (i.e. UIWebView - UILabel (Event Date) and UILabel (Event Date) - UIButton)
                  4. The container view has low priority (1) bottom vertical space constraint with its superview

                  我得到的结果如下:

                  UIWebView 展开但不下推事件日期标签和按钮,另外 Container 视图也不展开.

                  The UIWebView expands but does not push down the event date label and the button, plus the Container view does not expand either.

                  任何帮助将不胜感激.

                  您可以从此处下载示例 Xcode 项目.

                  推荐答案

                  您将 webView 的高度约束设置为 266.这就是为什么 web view 的高度仍然是固定的.

                  You are setting the height contraint of your webView as 266. That's why the height of the web view is still fixed.

                  您可以将此高度约束创建为 IBOutlet,例如:

                  You can create this height constraint as an IBOutlet, for example:

                  @property (weak, nonatomic) IBOutlet NSLayoutConstraint *webViewHeightConstraint;
                  

                  然后你可以在网页视图下载完内容后修改高度约束的常量.Web 视图本身由内部的滚动视图组成,因此如果您想获取内容的整体高度:

                  And then you can modify the constant of the height constraint when the web view has finished downloading the content. The web view itself consists of scroll view inside, so if you want to get the overall height of the content:

                  - (void)webViewDidFinishLoad:(UIWebView *)webView {
                      self.webViewHeightConstraint.constant = self.webView.scrollView.contentSize.height;
                  }
                  

                  或者显然这个也可以:

                  - (void)webViewDidFinishLoad:(UIWebView *)webView {
                      [self.webView sizeToFit];
                      self.webViewHeightConstraint.constant = self.webView.frame.size.height;
                  }
                  

                  这篇关于iOS 6 中具有自动布局的动态 UIView 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  quot;Auto Layout still required after executing -layoutSubviewsquot; with UITableViewCell subclass(“执行 -layoutSubviews 后仍需要自动布局带有 UITableViewCell 子类)
                  How do I animate constraint changes?(如何为约束更改设置动画?)
                  How do I size a UITextView to its content?(如何根据内容调整 UITextView 的大小?)
                  How to change the preferred language of an iPhone app in iOS 4(如何在 iOS 4 中更改 iPhone 应用程序的首选语言)

                      <tbody id='RSkhA'></tbody>
                  • <tfoot id='RSkhA'></tfoot>

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

                        <bdo id='RSkhA'></bdo><ul id='RSkhA'></ul>

                        <legend id='RSkhA'><style id='RSkhA'><dir id='RSkhA'><q id='RSkhA'></q></dir></style></legend>

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