Does AutoLayout work on ios 8 but not on ios 7?

I am using autolayout in a UICollectionViewCell. Super simple layout: only UILabel. I want UILabel to occupy the entire width minus 20 pixels of the insert and center in the cell both vertically and horizontally. I have set limits that do just that. If I run it on any iOS 8 device or simulator, it works great. However, when I run it on some ios 7 devices, the restrictions do not affect. I tried looking at Apple documents, but none of their changes seemed to be related to the auto route.

Here's the source code for the XML, although I doubt it means a lot:

<constraints> <constraint firstItem="OIc-cg-9hO" firstAttribute="leading" secondItem="Ga6-nx-lOn" secondAttribute="leading" constant="20" id="A7U-sd-fcL"/> <constraint firstAttribute="centerY" secondItem="OIc-cg-9hO" secondAttribute="centerY" id="G9e-9W-aDS"/> <constraint firstAttribute="centerX" secondItem="OIc-cg-9hO" secondAttribute="centerX" id="TrB-hI-7Kw"/> <constraint firstAttribute="trailing" secondItem="OIc-cg-9hO" secondAttribute="trailing" constant="20" id="yjH-nf-D9U"/> </constraints> 

More workaround than answer: but I added restrictions to the code as follows:

  [self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:1.0 constant:-20.0]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]]; 

For it to work, I need both coded constraints and IB constraints. Dunno why!

+5
source share
2 answers

Builder interface restrictions seem to use the Margin Limit option, which is not supported on iOS7. Open the constraints in IB and check if any of them are checked with the "relative to field" parameter.

See What is a “Margin Restriction” in a storyboard in Xcode 6 and What is a “ Margin Restriction” in a storyboard in Xcode 6 for more information on margin restriction.

+5
source

This happened to me, you need to check all the restrictions in the user interface and remove the relative margin that was introduced with iOS 8 and does not support iOS 7, do not forget those inside some places where you might forget (like UITableView cells) .

To find this option:

  • Click on UI Control

  • Go to the size inspector

  • Double-click any restriction and check the field, just turn it off and correct the restriction if something changes.

enter image description here

+4
source

Source: https://habr.com/ru/post/1203913/


All Articles