Dynamically setting layout on UICollectionView causes inexplicable contentOffset change

前端 未结 10 1638
一生所求
一生所求 2020-11-29 16:10

According to Apple\'s documentation (and touted at WWDC 2012), it is possible to set the layout on UICollectionView dynamically and even animate the changes:

10条回答
  •  孤城傲影
    2020-11-29 16:32

    Easy.

    Animate your new layout and collectionView's contentOffset in the same animation block.

    [UIView animateWithDuration:0.3 animations:^{
                                     [self.collectionView setCollectionViewLayout:self.someLayout animated:YES completion:nil];
                                     [self.collectionView setContentOffset:CGPointMake(0, -64)];
                                 } completion:nil];
    

    It will keep self.collectionView.contentOffset constant.

提交回复
热议问题