title: Update constraints for supplementary view of UICollectionView on orientation change
body: <p>I'm using a header (supplementary view) in my <code>UICollectionView</code>. On the header I have label which has a certain distance from the left side. I'm doing my calculation and setting the constant of a constraint. Everything does work as expected.</p>
  
  <p>If the orientation is now changed, the labels have the old position. Now I need to update the constraints for all my headers. Calling <code>invalidateLayout</code> doesn't update the constraints. How can I manually trigger the recalculation?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is how my <code>layoutSubviews</code> does look like, where the recalculation takes place:</p>
  
  <pre><code>public override void LayoutSubviews ()
  {
      this.width = this.collectionViewSize.Width;
      this.itemWidth  = (nfloat)Math.Round(this.width / numberOfItemsInRow);
  
      leftSpacing.Constant =  this.itemWidth * this.referencePoint;
      if (leftSpacing.Constant == 0)
          leftSpacing.Constant = SectionHeader.MIN_SPACING;
  
      base.LayoutSubviews ();
  }
  </code></pre>
  
  <p>As you can see this is not Objective-C but you should be able to see what I'm doing. I take the width of the collection view (set on instantiation of the supplementary view) and then I calculate the width of cell which corresponds nearly to the real size of the cells. With the <em>referencePoint</em> I determine the position. Here you can see the setup of my constraints:</p>
  
  <pre><code>public SectionHeader (CGRect frame) : base (frame)
  {
      this.width = frame.Size.Width;
      this.itemWidth  = (nfloat)Math.Round(width / numberOfItemsInRow);
  
      label = new UILabel (){
          BackgroundColor = UIColor.White,
          TextAlignment = UITextAlignment.Left
      };
  
      label.TranslatesAutoresizingMaskIntoConstraints = false;
      AddSubview (label);
  
      NSMutableDictionary viewsDictionary = new NSMutableDictionary();
      viewsDictionary["label"] = label;
  
      this.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|[label]|",(NSLayoutFormatOptions)0,null,viewsDictionary));
  
      leftSpacing = NSLayoutConstraint.Create(label, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, SectionHeader.MIN_SPACING);
      leftSpacing.Priority = 250;
      this.AddConstraint(leftSpacing);
      this.AddConstraint(NSLayoutConstraint.Create(label, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1, 0));
  }
  </code></pre>
  
  <p>In this code the calculation for the distance from the left is nearly the same, except that <em>frame</em> has the height of the set <code>headerReferenceSize</code>. The width should be OK for the initialisation. I'm using the full height for the label, I set up the leading space and I pin it to the right.</p>