简体   繁体   English

基于约束的iOS Update Interface Builder视图框架

[英]iOS Update Interface Builder view frame based on constraints

I am building my views in Interface Builder and I am using AutoLayout constraints. 我正在Interface Builder中构建视图,并且正在使用AutoLayout约束。 Whenever I create a Table View Cell I use Automatic Dimension so cell's heights are calculated properly. 每当创建表格视图单元格时,我都会使用“自动尺寸”,以便正确计算单元格的高度。

The problem is that cell frame in interface builder is not updating on its own (I mean the whole view's cell) 问题在于,界面构建器中的单元格框架无法自行更新(我是说整个视图的单元格)

Take look at this example: 看一下这个例子: 照片1 I've created a cell with a label, all vertical constraints are set and they're static. 我创建了一个带有标签的单元格,所有垂直约束均已设置,并且它们是静态的。 Top, Bottom, Height -> 20 + 20 + 30 = 70 points 顶部,底部,高度-> 20 + 20 + 30 = 70点

And this is fine, there are no errors in IB and cell is working. 很好,IB中没有错误,单元正在工作。 But the problem appears when I modify cell size in IB: 但是当我在IB中修改像元大小时出现了问题:

照片2 And errors appear causing the whole view not to behave properly. 并且出现错误,导致整个视图无法正常运行。 I would not like to change any of the constraints, but I'd like the whole view to shrink from that frame to frame displayed on the first photo where the frame height was 70 points. 我不想更改任何约束,但是我希望整个视图从该帧缩小到第一张照片上显示的帧,其中帧高为70点。

This is a problem on bigger and more complicated views, when I change a couple of constraints and I need to update frame manually. 当我更改几个约束并且需要手动更新框架时,这在更大和更复杂的视图上是一个问题。

What do I do right now to get rid of these errors is changing the priority of the last bottom constraint to 999, that works, but I'd really like to have IB to show this view as close as possible to a view calculated in runtime. 我现在要消除这些错误的方法是将最后一个底部约束的优先级更改为999,这是可行的,但是我真的很想让IB尽可能显示此视图与运行时计算的视图接近。

(I know that there us 'Update frames' button, but that does indeed change the subviews frames properly, but I'd like the superview, to update too) (我知道这里有“更新框架”按钮,但是确实确实可以正确更改子视图框架,但是我也希望超级视图也进行更新)

Aren't there any plugins or something that could help me building views that look just like at runtime? 没有任何插件或其他可以帮助我构建运行时外观的插件吗?

This problem happens when you try to shrink the view after you set hardcoded constraints so the cesl'height is not satisfying with the current constraints, so you see red lines. 当您在设置硬编码约束后尝试缩小视图时,会出现此问题,以使cesl'height不满足当前约束,因此您会看到红线。

The workaround is: every time you want to change any constraint inside the cell, remove the bottom most constraint, make the change, resize the cell yourself by dragging, then reconnect it again to the bottom of the content-view. 解决方法是:每次要更改单元格内的任何约束时,都应删除最底部的约束,进行更改,然后通过拖动自己调整单元格的大小,然后再次将其重新连接到内容视图的底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM