objective-cios7uicollectionviewautolayoutuicollectionviewcell

Ignored constraint on iOs 7 working on ios 8


I've been struggling with this issue for hours.

I'm using a simple CollectionView which has a custom cell with custom nib file. Also I set the size of the cell by doing this:

The Result in iOs8 The Result in iOs8

But in iOs 7 it seems that the center constraint I added to the view is totally ignored.
Actually it's acting like he doesn't listen to the constraint once the cell size is changed, in the collectionView:sizeForItemAtIndexPath: method.

Giving this unpleasant result:

Am I setting the constraints correctly? did I forget something like layoutIfNeeded or needsUpdateConstraints somewhere ?


Solution

  • I do answer myself,

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

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

    I do not understand the -1 since this is a real issue, I'm using Xcode Version 6.0 (6A313).

    I hope this will help someone having the same problem I did.