问题标签 [autolayout]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
6740 浏览

uilabel - How can I use Autolayout to create a layout that expands in height based on the content of a UILabel

I am attempting to build a dynamic layout using the new autolayout api in iOS 6.0. The layout that I am attempting to build has 2 buttons with a label inbetween them as shown in the image below:

enter image description here

What I would like is for the container view shown in grey to increase or decrease in size depending on the amount of text in the label.

So far I've managed to get the layout to work exactly as described with one small issue that I've not been able to resolve. The problem I am having is that the intrinsic height of the label is alway calculated with the original width of the label (e.g. the one set in interface builder) and not the width of the label that is set from the constraints I have on it.

The constraints that I have on the views are as follows:

  • H:|-[leftButton]-[label]-[rightButton]-|
  • Both buttons are centered Vertically
  • V: |-[label]-|
  • the content hugging priority of the buttons is higher than the label
  • the compression Resistance of the label is higher than the container view

All of these constraints together create the desired layout.

However:

  • If the Width of the label in interface builder (the literal size in interface builder) is less than the width of the view at runtime, then the height of the container is too large.

enter image description here

To help clarify this, the IB view of the above layout was as follows (note much narrower)

enter image description here

  • If the Width of the label in interface builder (the literal size in interface builder) is greater than the width of the view at runtime, then the height of the container is too small and lines of text get cut off.

What appears to be happening is that although there is no constraint on the labels width, the label seems to calculate its height (and thus the autolayout calculated height of the container) based on the original width of the label when it was created. However whats so strange is that the text appears to be the correct width and height but the label itself has a frame thats just too big or small.

I guess this is related to the order in which things are happening, and have tried calling updateConstraintsIfNeeded in the containerViews layoutSubview method however this doesn't appear to do anything.

Any suggestions would be greatly appreciated.

0 投票
12 回答
20060 浏览

ios - 旋转在 iOS6 上表现不同

我做了一个基于标签的应用程序。什么都不需要在横向模式下,只需要几个视图。它在 iOS5 上运行良好,我对结果非常满意。然而,使用 iOS6 并且没有弄乱任何东西,它现在会旋转所有视图,结果并不好。

因为它是一个基于选项卡的应用程序,所以我在横向中需要的几个视图是 modalViews。这样我就不会弄乱标签栏,我只需要在构建选项的“支持的方向”设置中选择肖像并设置:

关于我想要的风景。

现在有了 iOS6,这个视图也处于纵向模式,无论如何,即使我旋转设备,它们也不会显示横向模式。同样,如果我允许“支持的方向”上的所有方向,它们都会旋转,无论我在上面的方法中使用什么。

在所有视图中,我都没有选中情节提要上的“使用自动布局”框。

这里有什么帮助吗?

*编辑** 现在我看到了,我在设备上的应用程序运行良好。我已经安装了促销代码,而不是来自 Xcode,只是为了查看我的客户是否有问题。幸运的是,他们不是。但问题仍然存在。

0 投票
7 回答
4940 浏览

ios - 故事板中的 UITableView 不更新旋转时的内容大小

我正在开发针对 iOS 6 的项目,该项目利用了故事板和自动布局。在故事板中有很多地方将 UITableView 作为子视图添加到视图控制器视图中。此表视图使用情节提要中的原型单元格。

我们遇到的问题是,如果视图控制器最初以横向加载,然后设备旋转为纵向,则表格视图开始垂直和水平滚动。表格视图单元格以正确的尺寸绘制,但右侧有额外的空白。

看起来,虽然表格视图的框架和边界在旋转时被更新为正确的大小,但表格视图的内容大小却没有。无论更新旋转如何更改,内容大小都保持相同的尺寸。

如果使用程序化表格视图单元格,则不会出现此问题。我发现了一些花哨的解决方法,1.) 调用 reloadData 或 reloadRowsAtIndexPaths:withRowAnimation: 2.) 手动设置属性 contentSize。

这两个似乎都不理想。

我已将此链接添加 到一个演示此问题的简单示例项目中。所做的唯一更改是故事板和主视图控制器的实现。

旋转前 旋转 旋转前旋转后

0 投票
2 回答
363 浏览

iphone - 如果更改视图框架,为什么所有已经设置的自动布局约束都消失了?

在此处输入图像描述

如屏幕截图所示,我制作了所有 4 个视图widths equallyheight equally然后如果我更改绿色视图的帧大小,所有其他约束Horizontal spacingvertical spacing消失了,我必须从头开始,所有视图都可以在纵向和横向上工作。

同样在那之后我再次设置所有约束并且仍然处于横向模式标签没有正确显示,如屏幕截图所示在此处输入图像描述

我设置了这些约束。在此处输入图像描述

有什么我想念的吗?

0 投票
2 回答
2414 浏览

ios - iOS 6 中自动布局的动态大小

我想要一个视图,其大小(在本例中为高度)取决于屏幕大小,以用一个 xib 覆盖 iPhone4/iPhone6 的屏幕。所以可以说我拿了一个 ListView 并且我不想让它全屏显示,但我在上面和下面有固定的空间。那么它的高度应该是:

在 Interface Builder 中,我可以设置两个垂直空间约束,然后甚至删除 ListView 的高度约束,因此它的高度由父视图和这两个空间约束确定。

在模拟指标中设置 Freeform 后,我可以拖动以更改根视图的大小并查看约束是否正常工作(ListView 正确调整大小)。

问题:

但是,如果我在模拟器中运行该应用程序,那么一切都将固定在 Interface Builder 中的最后一个位置。我错过了什么阻止布局根据其约束工作?

如果我将模拟指标更改为 Retina 3.5 或 4,Xcode 会删除我的约束并返回到固定大小的约束。

0 投票
1 回答
1803 浏览

storyboard - 简单的 3.5 英寸 + 4 英寸 iPhone 屏幕布局需要自动布局?

我正在将旧应用程序更新为新的 iPhone 尺寸,但遇到了问题。自动布局打破了旧故事板的几块。

没问题,只需进入并取消选中自动布局。再次运行(3.5 英寸屏幕)并再次完美运行,然后在 4 英寸屏幕中运行,没有任何重新调整大小。花接下来的几分钟检查和取消选中自动布局框并在各种屏幕上运行它。这显然是问题所在。

关闭自动布局,在视图控制器中选择顶视图,打开尺寸检查器检查器并查看 Autosizing 框。让视图重新调整大小的内部箭头显示为灰色。你不能选择它们。从示例视图看,很明显视图不会重新调整大小。由于它不会重新调整大小,因此无法在 3.5 英寸和 4 英寸屏幕上正常工作。

有人看到绕过这个限制的(相当简单的)方法吗?

我真的不想更新不需要 UI 更新才能与自动布局一起正常工作的故事板,但另一个选择似乎是编写测试代码并将其放入我所有的视图控制器中,这可能与修复我所有的故事板以使用自动布局。

0 投票
1 回答
1656 浏览

objective-c - 如何停止使用自动布局调整 NSView 子视图的大小

我在使用新的自动布局功能时遇到问题。我添加了一个名为 tableView 的 NSView 作为 workingBox 的子视图。workingBox 还包含一些其他使用 Interface Builder 添加的子视图

我的问题是,如果任何其他子视图触摸 tableView,那么它们将在动画中调整大小。不在添加 tableView 的位置附近的子视图保持正确的大小。我已经尝试在正在调整大小的子视图上设置 NSViewNotSizable resizeMask 但它不起作用。唯一有效的是将子视图向上移动(到错误的位置。


编辑:我在代码中添加了一个约束:

这使 NSView 保持在 1px 高度,但如果我将其锁定在顶部,它会阻止超级视图增长

0 投票
3 回答
1199 浏览

iphone - 使用自动布局导致按钮停止工作

我试图为我的 .xib 文件中的视图添加使用自动布局功能,目标是根据正确的屏幕尺寸调整视图。

当我将自动布局添加到视图并设置自由格式并将视图大小更改为 568 时,视图在 iPhone 5 模拟器上看起来正确,但是当尝试按下底部的按钮时,如果我在 iPhone 4 上运行相同的应用程序,它们将不起作用视图看起来正确并且按钮正在工作。

我错过了什么?任何人都知道教程或我在哪里可以找到如何在没有自动布局的情况下转换常规 xib 工作的信息?

0 投票
9 回答
18690 浏览

iphone - UIScrollview 自动布局问题

我的自动布局(可能)和我的滚动视图有问题!

我的问题

  1. 我向下滚动 看法

2.然后我推送到另一个视图

3.然后我回去,滚动视图看起来像那样,我无法滚动到最高点。(我在滚动视图的弹跳中看到它) 滚动视图

有谁能够帮我?

0 投票
1 回答
2611 浏览

ios - 我想移动指定自动布局的视图的位置。(ios6,xcode4.5)

我想指定中心的坐标。

在上面的代码中,motherButton 没有移出屏幕。

你怎么去?我想在动画中移动。