Nested UICollectionViews, AutoLayout and rotation in iOS 8

后端 未结 7 980
青春惊慌失措
青春惊慌失措 2021-02-03 16:20

I started to use AutoLayout for a large project and was positively surprised about it. However, now I have to adjust the project to accommodate for rotation and size classes, an

7条回答
  •  旧时难觅i
    2021-02-03 16:46

    Answering my own question here - I finally found the solution. For any others who are having troubles with this here is what I did:

    The main part lies in putting invalidateLayout and reloadData calls in the right places:

    • Put an invalidateLayout on the base collectionView's layout in the willTransitionToSize function.
    • Put a reloadData on the base collectionView in the completion block of a coordinator animateAlongsideTransition: call in the willTransitionToSize function.
    • Make sure the autolayout constraints for any views in the cells are set right - I connected the cell view with autolayout constraints to the cell's content view in code.
    • In case you overwrote the prepareLayout function of the collection view layout, make sure the pre-calculated cell sizes use the right width, I used a wrong width here which lead to some additional problems.

提交回复
热议问题