Animating UICollectionView contentOffset does not display non-visible cells

后端 未结 7 2104
旧巷少年郎
旧巷少年郎 2021-02-01 18:31

I\'m working on some ticker-like functionality and am using a UICollectionView. It was originally a scrollView, but we figure a collectionView will make it easier

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 19:10

    You should simply add [self.view layoutIfNeeded]; inside the animation block, like so:

    [UIView animateWithDuration:((self.collectionView.collectionViewLayout.collectionViewContentSize.width - self.collectionView.contentOffset.x) / 75) delay:0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState) animations:^{
                self.collectionView.contentOffset = CGPointMake(self.collectionView.collectionViewLayout.collectionViewContentSize.width, 0);
                [self.view layoutIfNeeded];
            } completion:nil];
    

提交回复
热议问题