• 使用UICollectionView遇到的各种坑




    1)头视图和尾部视图的添加
    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];

    UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView" forIndexPath:indexPath];

    2)内嵌(需求就是UICollectionView没有像Tableview一样的TabHeaderView),想要制造一个

    contentInset


    3)没有注册
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
    [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];
    2.使用UICollectionView遇到的复用问题

    1)头视图的使用
    for (UIView *view in headerView.subviews) {
    [view removeFromSuperview];
    }

    for (UIView *view in footerView.subviews) {
    [view removeFromSuperview];
    }

    2)cell的复用

    KnowledgeBasePopCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KnowledgeBasePopCell" forIndexPath:indexPath];


    3.使用UICollectionView不走代理的问题

    1)item尺寸计算错误



    2)禁止使用0.01这种尺寸

    //每个item之间的间距
    -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

    return 0.01;
    }

    //定义每个Section 的 margin
    -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{


    return UIEdgeInsetsMake(0.01,0.01,0.01,0.01);
    }


    上述两个是不走-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{



    3)在window上添加view,view上添加UICollectionView,是不走-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{


    使用各种手势冲突判断解决方法,但是都没有效果

    是UICollectionViewCell视图?
    是UICollectionView类?
    都不能捕捉到点击事件

    解决方法:
    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    if ([touch.view isDescendantOfView:self.collectionView]) {
    return NO;
    }
    return YES;
    }

    4。使用UICollectionView组头也可以悬停

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //header
    flowLayout.sectionHeadersPinToVisibleBounds = YES;
    //footer
    flowLayout.sectionFootersPinToVisibleBounds = YES;

    问题:这仅在iOS9中才支持这种设置

    by:ml

  • 相关阅读:
    利用FlashPaper实现类似百度文库功能
    浅谈Oracle函数返回Table集合
    Oracle 触发器在日志管理开发中的应用
    Putty 工具 保存配置的 小技巧
    java.util.Date转java.sql.Date丢失时间问题
    java String和Date转换
    springboot项目使用拦截器修改/添加前端传输到后台header和cookie参数
    Spring的使用及Spring3.2控制器增强@ControllerAdvice
    使用fastjson统一序列化响应格式
    【转】Elastic-Job
  • 原文地址:https://www.cnblogs.com/widgetbox/p/10045362.html
Copyright © 2020-2023  润新知