关于UICollectionViewFlowLayout布局的问

2016-11-29  本文已影响0人  HCL黄
  /** 懒加载 */
  - (UICollectionViewFlowLayout *)layout
  {
    if (_layout == nil) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
        _layout.minimumLineSpacing = kMargin;
        _layout.minimumInteritemSpacing = kMargin;
    }
    return _layout;
}
  - (UICollectionView *)collectionView
{
    if (_collectionView == nil) {
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.layout];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.backgroundColor = RGBA(230, 230, 230, 1);
        
        // 注册cellHomeNormalCell
        [_collectionView registerNib:[UINib nibWithNibName:@"HomeNormalCell" bundle:nil] forCellWithReuseIdentifier:HomeCellNormalID];
        // 注册满屏的
        [_collectionView registerNib:[UINib nibWithNibName:@"HomeFullCell" bundle:nil] forCellWithReuseIdentifier:HomeCellFullID];
        // 注册有组头的cell
        [_collectionView registerNib:[UINib nibWithNibName:@"HomeSectionCell" bundle:nil] forCellWithReuseIdentifier:HomeCellSectionID];
        // 注册headerView
        [_collectionView registerNib:[UINib nibWithNibName:@"HomeReusableHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HomeHeaderViewID];
    }
    return _collectionView;
}


  - (void)viewDidLoad {
    [super viewDidLoad];
    // 不需要额外的滚到区域
    self.automaticallyAdjustsScrollViewInsets = NO;
    // 添加collectionView
    [self.view addSubview:self.collectionView];
}

  - (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    // layout的frame
    self.layout.itemSize = CGSizeMake(normalW, normalH);
    self.layout.sectionInset = UIEdgeInsetsMake(0, kMargin, 0, kMargin);
    // collectionView的Frame
    self.collectionView.frame = CGRectMake(0, 64, kScreenW, kScreenH - kTabBarH);
}
QQ20161129-1@2x.png
QQ20161129-2@2x.png
QQ20161129-3@2x.png
  - (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    // layout的frame
    //self.layout.itemSize = CGSizeMake(normalW, normalH);
    //self.layout.sectionInset = UIEdgeInsetsMake(0, kMargin, 0, kMargin);

    // collectionView的Frame
    self.collectionView.frame = CGRectMake(0, 64, kScreenW, kScreenH - kTabBarH);
}
QQ20161129-0@2x.png
上一篇 下一篇

猜你喜欢

热点阅读