1
votes

Four UIViews(v1,v2,v3,v4) are inside UITableViewCell. Cell has constraints: v1.width/v2.width, v1.width/v3.width, v1.width/v4.width and horizontal distances between views and to superview (x-v1-x-v2-x-v3-x-v4-x).

Views widths must calculated directly from cell content view width. And they are calculated correctly in iOS8 and randomly in iOS7. It happens if views are inside UIView too(not UITableViewCell). Why it happens and how to support iOS7 in this case?

UPDATE Content Hugging Priority for all views - 250. Content Compression Resistance Prioriry for all views - 750. All my custom constraints priority - 1000. Horizontal constraints for inner view:

ios7:

    "<NSLayoutConstraint:0x7fc84bf6bf30 H:|-(0)-[UIView:0x7fc84bf6b990]   (Names: '|':UITableViewCellContentView:0x7fc84bf6b8d0 )>",
"<NSLayoutConstraint:0x7fc84bf6bee0 UIView:0x7fc84bf6b990.width == 1.2*UIView:0x7fc84bf6baf0.width>",
"<NSLayoutConstraint:0x7fc84bf6aed0 UIView:0x7fc84bf6b990.width == 1.4*UIView:0x7fc84bf6bc10.width>",
"<NSLayoutConstraint:0x7fc84bf6bf80 UIView:0x7fc84bf6b990.width == 1.8*UIView:0x7fc84bf6bd30.width>",
"<NSLayoutConstraint:0x7fc84bf6bfd0 H:[UIView:0x7fc84bf6b990]-(8)-[UIView:0x7fc84bf6baf0]>",
"<NSLayoutConstraint:0x7fc84bf6c020 H:[UIView:0x7fc84bf6baf0]-(5)-[UIView:0x7fc84bf6bc10]>",
"<NSLayoutConstraint:0x7fc84bf6c070 H:[UIView:0x7fc84bf6bd30]-(12)-|   (Names: '|':UITableViewCellContentView:0x7fc84bf6b8d0 )>",
"<NSLayoutConstraint:0x7fc84bf6c0c0 H:[UIView:0x7fc84bf6bc10]-(5)-[UIView:0x7fc84bf6bd30]>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc84bf14260 h=--& v=--& H:[UITableViewCellContentView:0x7fc84bf6b8d0(320)]>"

ios8:

    "<NSLayoutConstraint:0x78ed1b70 H:|-(0)-[UIView:0x78ed24f0]   (Names: '|':UITableViewCellContentView:0x78ed1dd0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x78ecfa70 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x78ed1dd0]   (Names: '|':TableViewCell:0x78ed2350 )>",
"<NSLayoutConstraint:0x78ed2730 UIView:0x78ed24f0.width == 1.2*UIView:0x78ed2560.width>",
"<NSLayoutConstraint:0x78ed1cb0 UIView:0x78ed24f0.width == 1.4*UIView:0x78ed25d0.width>",
"<NSLayoutConstraint:0x78ed2760 UIView:0x78ed24f0.width == 1.8*UIView:0x78ed2640.width>",
"<NSLayoutConstraint:0x78ed2790 H:[UIView:0x78ed24f0]-(8)-[UIView:0x78ed2560]>",
"<NSLayoutConstraint:0x78ed27c0 H:[UIView:0x78ed2560]-(5)-[UIView:0x78ed25d0]>",
"<NSLayoutConstraint:0x78ed27f0 H:[UIView:0x78ed2640]-(12)-|   (Names: '|':UITableViewCellContentView:0x78ed1dd0 )>",
"<NSLayoutConstraint:0x78ed2820 H:[UIView:0x78ed25d0]-(5)-[UIView:0x78ed2640]>",
"<NSLayoutConstraint:0x78ebb880 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x78ed1dd0(320)]>"

ios8

ios7

2
We're going to need to see your constraints to debug this. Show us the output of constraintsAffectingLayoutForAxis: UILayoutConstraintAxisHorizontal for one cell's content view. - rob mayoff
I have updated my post. - vojer
Is that output for one of the correct cells, or one of the incorrect cells? Show both. - rob mayoff
It is an output for either cell. Difference is only in ios7/8. - vojer

2 Answers

1
votes

With the information you've posted so far, this looks like a bug in the iOS 7 layout engine that was fixed in iOS 8.

I base this guess on the fact that your constraints are the same between iOS 7 and iOS 8, and are unambiguous, and work correctly in iOS 8.

Specifically, if we call the width of the gray view w, then the horizontal layout is determined by solving for w in

0 + 8 + 5 + 5 + 12 + w + w/1.2 + w/1.4 + w/1.8 = 0.

Plugging this into Wolfram Alpha gives w = 36540/391 ≈ 93.453, a unique solution. The widths of the views would then ideally be approximately 93.453, 78.877, 66.752, and 51.918. However, the layout engine rounds these to pixel boundaries. In my testing, the views end up with widths 93.5, 79.0, 66.5, and 52.0.

You can either set your deployment target to iOS 8.0, or you can manually lay out those subviews. I don't expect Apple to issue a new iOS 7 release that fixes this.

0
votes

Make sure you are calculating using bounds as a rect, not frame. edited: Now I see you are using autolayout. Are you able to post your hugging and compression resistance priorities?