title: Can I use a UICollectionViewCell as an autolayout constraint item?
body: <p>I have a view controller with a view that contains a UICollectionView and a UIImageView.</p>
  
  <p>The UICollectionView and the image view are siblings in the UIViewController's managed view. As the user scrolls the UICollectionView around, the UIImage should sometimes attach itself to the bottom of one of the UICollectionViewCell items.</p>
  
  <p>I'm converting the project to use auto layout and I was really excited to be able to use constraints to attach the UIImageView to the bottom of a UICollectionViewCell.  However, it doesn't seem to be working.  </p>
  
  <p>When the code detects that the relevant UICollectionViewCell has become visible it removes the previous positioning constraints from the UIImageView and adds a constraint that makes the top of the UIImageView be the same as the bottom of the UICollectionViewCell.</p>
  
  <p>When that happens the UIImageView just disappears. I think that it's being attached to the UICollectionViewCell before the cell is visible, but that's ok, it should then scroll into view with it.  That's not happening.</p>
  
  <p>So my question is this ... can this EVER work?  It seems to me that there is a very strong possibility that the UICollectionView is managing it's items using the old fashioned center/bounds system.  Specially if you look at the UICollectionViewLayout protocol.  Does that mean that I can't attach a constraint to a UICollectionViewCell and expect the constraint to be updated as the cell is moved within the collection view?</p>
  
  <p>I'm attaching the relevant code below in case it's a simple coding issue instead of a higher level "you're going back to the drawing board" one.</p>
  
  <pre><code>    if([collectionView.indexPathsForVisibleItems containsObject:self.sliderPositionIndex]){
      UICollectionViewCell *lockedCell=[collectionView cellForItemAtIndexPath:self.sliderPositionIndex];
      [self.view removeConstraint:self.sliderVerticalSpaceConstraint];
      self.sliderVerticalSpaceConstraint=[NSLayoutConstraint constraintWithItem:self.sliderTab
                                                                        attribute:NSLayoutAttributeTop
                                                                        relatedBy:NSLayoutRelationEqual
                                                                           toItem:lockedCell
                                                                        attribute:NSLayoutAttributeBottom
                                                                       multiplier:1
                                                                         constant:0];
      [self.view addConstraint:self.sliderVerticalSpaceConstraint];
      [self.view setNeedsUpdateConstraints];
  </code></pre>