简体   繁体   中英

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. Here's the problem...

I am trying to create a dynamic sizing cell having an UIImageView of certain aspect ratio(6:5). 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). 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.

这里

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. 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? Any help is much appreciated.

Add constraint like this on your imageview and separator view

在此处输入图片说明

Ex. Add 4 constraint on separator view

  1. Leading
  2. Top
  3. Bottom
  4. height

and add 5 constraint on imageview

  1. Leading
  2. Top
  3. Bottom
  4. height
  5. Aspect ratio with priority 750

you can change priority after adding aspect ratio constraint from size inspector

在此处输入图片说明

after this add this code in viewDidLoad Method

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

Now all error gone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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