Nested UICollectionViews, AutoLayout and rotation in iOS 8

后端 未结 7 960
青春惊慌失措
青春惊慌失措 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条回答
  •  误落风尘
    2021-02-03 16:41

    Thanks to TheEye. I wanted to add this as a comment to their response, but apparently I don't have enough Karma (yet), So consider this an addendum.

    I was having the same problem, however the cells in my uicollectionview have an "expanded state" when selected. if the user rotates the device and we call [self.collectionview reloadData], any cells that are expanded will lose their state. You can optionally call performBatchUpdates and force the collection view to layout without losing the state of any cell

    -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator{
    [self.collectionView.collectionViewLayout invalidateLayout];
    
    [coordinator animateAlongsideTransition:^(id context) {
    
    } completion:^(id context) {
        //[self.collectionView reloadData];//this works but reloading the view collapses any expanded cells.       
        [self.collectionView performBatchUpdates:nil completion:nil];       
    }];  
    }
    

提交回复
热议问题