Keeping the contentOffset in a UICollectionView while rotating Interface Orientation

后端 未结 24 1391
野性不改
野性不改 2020-12-04 07:22

I\'m trying to handle interface orientation changes in a UICollectionViewController. What I\'m trying to achieve is, that I want to have the same contentOffset afte

24条回答
  •  清歌不尽
    2020-12-04 08:08

    My way is to use a UICollectionViewFlowlayout object.

    Set the ojbect line spacing if it scrolls horizontally.

    [flowLayout setMinimumLineSpacing:26.0f];
    

    Set its interitem spacing if it scrolls vertically.

    [flowLayout setMinimumInteritemSpacing:0.0f];
    

    Notice it behaves different when you rotate the screen. In my case, I have it scrolls horizontally so minimumlinespacing is 26.0f. Then it seems horrible when it rotates to landscape direction. I have to check rotation and set minimumlinespacing for that direction 0.0f to make it right.

    That's it! Simple.

提交回复
热议问题