美文网首页
UICollectionView的一些记录

UICollectionView的一些记录

作者: 流星阁 | 来源:发表于2021-06-29 15:03 被阅读0次

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

    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];
    

    相关文章

      网友评论

          本文标题:UICollectionView的一些记录

          本文链接:https://www.haomeiwen.com/subject/fgxkultx.html