简体   繁体   English

Xcode 7.3自动布局问题

[英]Xcode 7.3 Autolayout Issue

Ever since I switched to Xcode 7.3 my life has become a living hell as Xcode started showing autolayout constraint issues in my layouts which were working fine in Xcode 7.2 and even after searching a lot I couldn't find a solution. 自从我切换到Xcode 7.3之后,我的生活就变成了一个活生生的地狱,因为Xcode开始在我的布局中显示自动布局约束问题,这些问题在Xcode 7.2中仍然可以正常工作,即使经过大量搜索,我仍然找不到解决方案。 Here's the problem... 这是问题所在...

I am trying to create a dynamic sizing cell having an UIImageView of certain aspect ratio(6:5). 我正在尝试创建具有一定长宽比(6:5)的UIImageView的动态大小调整单元格。 Below the image is a 1px height UIView that show as a separator(I cannot use the default separator for some reason so this is a must). 图像下方是一个高度为1px的UIView,它显示为分隔符(由于某种原因,我无法使用默认分隔符,因此这是必须的)。 Here are the constraints. 这里是约束。

这里是约束

I assume that with these constraints the height of the cell can be calculated dynamically whenever the cell is shown. 我假设在这些约束下,只要显示了单元格,便可以动态计算单元格的高度。 This all is very simple and works as expected if built using Xcode 7.2 but Xcode 7.3 shows warning at runtime. 所有这些都非常简单,并且如果使用Xcode 7.2构建,则可以按预期工作,但是Xcode 7.3在运行时显示警告。

这里

Most of the time the views are shown perfectly but in few cases, because constraints are broken at runtime, views are laid out of their place. 大多数情况下,视图可以完美显示,但是在少数情况下,由于约束在运行时会被破坏,因此视图会摆在原处。 This is more of a general problem and is happening with almost all of my UITableViewCells. 这更是一个普遍的问题,几乎所有的UITableViewCells都在发生这种情况。 This particular example is the simplest of them all. 这个特定示例是所有示例中最简单的一个。 Anyone with decent know how of autolayout cannot make a mistake in setting correct constraints...so is there anything wrong with my constraints or is there anything wrong with Xcode, and more importantly how to solve this issue? 任何体面的人都知道自动布局的方法不会在设置正确的约束时犯错误...所以约束有问题还是Xcode有问题,更重要的是如何解决此问题? Any help is much appreciated. 任何帮助深表感谢。

Add constraint like this on your imageview and separator view imageview separator viewseparator view上添加这样的约束

在此处输入图片说明

Ex. 防爆。 Add 4 constraint on separator view 在分隔符视图上添加4个约束

  1. Leading 领导
  2. Top 最佳
  3. Bottom 底部
  4. height 高度

and add 5 constraint on imageview 并在imageview上添加5个约束

  1. Leading 领导
  2. Top 最佳
  3. Bottom 底部
  4. height 高度
  5. Aspect ratio with priority 750 宽高比为750

you can change priority after adding aspect ratio constraint from size inspector 您可以从大小检查器添加纵横比约束后更改优先级

在此处输入图片说明

after this add this code in viewDidLoad Method 之后,将此代码添加到viewDidLoad方法中

  self.table.estimatedRowHeight =  304.0f;
  self.table.rowHeight = UITableViewAutomaticDimension;

Now all error gone 现在所有错误消失了

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

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