Ignored limitation on iOs 7 running on ios 8

I have been wrestling with this problem for hours.

I am using a simple CollectionView that has a custom cell with a custom nib file. Also I set the cell size by doing the following: - (CGSize)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return collectionView.frame.size; }

I'm just trying to center the subview in the cell and while it works fine in iOs8 the point of view is centered and I even call reloadData

in viewWillTransitionToSize:

, so the cell size is updated when rotated.

Result in iOS8 The Result in iOs8

But in iOs 7, it seems like the central constraint I added to the view is being completely ignored.
In fact, it acts as if it is not listening to the constraint after the cell is resized in the method collectionView:sizeForItemAtIndexPath:

.

Providing this annoying result:

Am I setting the limits correctly? I forgot something like layoutIfNeeded

or needsUpdateConstraints

somewhere?

You can download a simple tiny project here that has my problem. http://goo.gl/mBmI1H

Thank you for your help.

+3


source to share


1 answer


I answer myself

I actually solved the problem by removing the center constraints in the interface builder and adding them to the code like this:

[self addConstraint:
 [NSLayoutConstraint constraintWithItem:self
                              attribute:NSLayoutAttributeCenterX
                              relatedBy:0
                                 toItem:self.connectedContainer
                              attribute:NSLayoutAttributeCenterX
                             multiplier:1
                               constant:0]];

      



I don't understand -1 since this is a real problem, I am using Xcode Version 6.0 (6A313).

I hope this helps someone else having the same problem.

+3


source







All Articles