zoukankan      html  css  js  c++  java
  • 使用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

  • 相关阅读:
    java学习 接口与继承11 默认方法
    java学习 接口与继承10 内部类
    java学习 接口与继承9 抽象类
    java学习 接口与继承8 final
    理解管理信息系统
    vue中的错误日志
    vue中的ref属性
    2.有24颗外观完全一样的小球,其中有一个是空心的,现在只有一个天平,最少称几次能找出这个特殊的球?
    1.有888瓶编了号码的水及10只健康的小白鼠,其中一瓶水有毒,小白鼠饮用毒水一天后会死,最少需要几天可以找到哪瓶水有毒?
    SQL题1两表联查
  • 原文地址:https://www.cnblogs.com/widgetbox/p/10045362.html
Copyright © 2011-2022 走看看