2
votes

I have a simple UICollectionView using UICollectionViewFlowLayout. It also has a section supplementary view of kind UICollectionElementKindSectionHeader. When the section header is visible on screen and device is rotated, the constraints adjusts the sub-views of the header correctly.

If I scroll away such that the section header is not visible on screen, rotate the device and scroll back to see the header view, the constraints of the sub-views do not update and adjust sub-views position according to the device rotation. Is there a fix to this?

Essentially the header view (supplementary view) trailing space constraints with respect to the UICollectionView is not taking effect, this is how header view (white bar on top) looks like:

enter image description here

1
Try calling layoutSubviews in your collectionView, or in your header view if you have a reference to it. - EmilioPelaez
@EmilioPelaez tried all those type of methods but doesn't help - 2cupsOfTech

1 Answers

1
votes

I know in auto-layouts one should not be explicitly setting frame but for now writing the following piece of code inside -UIViewController viewWillTransitionToSize: works

CGRect frame = header.frame;
frame.size.width = size.width;
header.frame = frame;

Looking for a better solution from anyone.