When is the appropriate moment in rotation to change the Layout parameters of a UICollectionView

前端 未结 1 447
北海茫月
北海茫月 2021-02-09 02:53

Hopefully a simple question for a relatively new UIKit control

I have a UICollectionView that has a viewLayout with a single row o

相关标签:
1条回答
  • 2021-02-09 03:30

    I'm working on a similar problem.

    Currently, my UICollectionViewController has two instance variables of UICollectionViewFlowLayout, each with the appropriate insets for portait or landscape.

    On rotation, I do this:

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                   duration:(NSTimeInterval)duration{
    
        if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) {
            [_itemCollection setCollectionViewLayout:_portraitLayout];
            [_itemCollection reloadData];
        } else {
            [_itemCollection setCollectionViewLayout:_landscapeLayout];
            [_itemCollection reloadData];
        }
    }
    

    The only problem that I'm having is that it randomly crashes with exc_bad_access on setCollectionViewLayout randomly.

    Something like the above might work for you. I'm not sure if this is the right way to do things. I have only recently started using UICollectionViews.

    0 讨论(0)
提交回复
热议问题