UICollectionView的一些记录

一.数据不满一屏时滑动需开启以下属性

collectionView.alwaysBounceVertical=YES;// 垂直
collectionView.alwaysBounceHorizontal=YES;// 水平

二.刷新闪烁问题

1.用WithoutAnimation进行刷新,仅IOS7+以上(建议使用)

[UIView performWithoutAnimation:^{
   //刷新界面
    [self.collectionView reloadData];
 }];

2.performBatchUpdates仅支持刷新当前变更的数据源,若调用reloadData刷新会报如下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (9) must be equal to the number of items contained in that section before the update (8), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out)

[UIView animateWithDuration:0 animations:^{
  [collectionView performBatchUpdates:^{
    [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
  } completion:nil];
}];
  [UIView animateWithDuration:0 animations:^{
  [collectionView performBatchUpdates:^{
    [collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
  } completion:nil];
}];

3.同上

注:该方法使用不当会造成UIview隐世动画消失

    [UIView setAnimationsEnabled:NO];
    [collectionView performBatchUpdates:^{
      [collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
    } completion:^(BOOL finished) {
      [UIView setAnimationsEnabled:YES];
    }];

以上方法都只针对UIView隐世动画

4.针对使用了CALayer的动画的取消刷新闪烁问题

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    [collectionView reloadData];
    [CATransaction commit];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容