collectionview通過設定contentInset方式添加表頭Header,影響MJRefresh使用的解決方案

來源:互聯網
上載者:User


//1.代碼

- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.isShowSortList =NO;

    self.title =@"熱銷商品";

    self.navigationController.navigationBar.translucent = NO;

    //擷取枚舉

    self.pageSize =10;

    self.pageNo =1;

    //排序類表

    MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];

    [RegisterHttpToolgetEnumsWithEnumAttr:@"PRODUCT_SORT_TYPE"success:^(EnumListDTO *result) {

        [hud hide:YES];

        [self.enumsremoveAllObjects];

        self.enums = result.enums;

#pragma mark ---繪畫collectionview---和頭部輪播圖選擇按鈕

        //CollectionView

        self.flowLayout = [[UICollectionViewFlowLayoutalloc]init];

        self.flowLayout.itemSize =CGSizeMake((SCREEN_SIZE_WIDTH-5)/2, (SCREEN_SIZE_WIDTH-5)/2*(462.0/370));

        self.flowLayout.minimumLineSpacing =5;

        self.flowLayout.minimumInteritemSpacing =5;

        self.myCollectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,0, SCREEN_SIZE_WIDTH,SCREEN_SIZE_WIDTH) collectionViewLayout:self.flowLayout];

        self.myCollectionView.delegate =self;

        self.myCollectionView.dataSource =self;

        self.myCollectionView.backgroundColor =NORMAL_BKG_GREY;

        [self.viewaddSubview:self.myCollectionView];

        [self.myCollectionViewmas_makeConstraints:^(MASConstraintMaker *make) {

            make.edges.mas_equalTo(self.view);

        }];

        [self.myCollectionViewregisterClass:[ShopSearchResultCellclass] forCellWithReuseIdentifier:@"ShopSearchResultCell"];

       //下拉(解決設定contentInset 遮擋mj_header顯示關鍵代碼)

        MJRefreshNormalHeader *ref_header =[MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(makeTheTabDown:)];

        ref_header.ignoredScrollViewContentInsetTop = (SCREEN_SIZE_WIDTH*2/5+43+1);

        self.myCollectionView.mj_header = ref_header;

        //上拉載入

        self.myCollectionView.mj_footer = [MJRefreshAutoFooterfooterWithRefreshingTarget:selfrefreshingAction:@selector(makeTheTabUp:)];

        self.myCollectionView.contentInset =UIEdgeInsetsMake(SCREEN_SIZE_WIDTH*2/5+43+1,0, 0,0);

        [selfgetDataFromSever];

        

        //輪播圖(w/h為3/2)

        UIView *lunBoView = [[UIViewalloc]init];

        [self.myCollectionViewaddSubview:lunBoView];

        lunBoView.backgroundColor = [UIColoryellowColor];

        [lunBoView mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(-(SCREEN_SIZE_WIDTH*2/5+43+1));

            make.left.mas_equalTo(self.myCollectionView);

            make.width.mas_equalTo(SCREEN_SIZE_WIDTH);

            make.height.mas_equalTo(SCREEN_SIZE_WIDTH*2/5);

        }];

        self.imgvScrollView = [[SDCycleScrollViewalloc]init];

        [lunBoView addSubview:self.imgvScrollView];

        self.imgvScrollView.delegate =self;

        self.imgvScrollView.autoScroll =YES;

        self.imgvScrollView.showPageControl =YES;

        self.imgvScrollView.infiniteLoop =YES;

        self.imgvScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;

        self.imgvScrollView.placeholderImage =[UIImageimageNamed:@"placeholder_img"];

        

        [self.imgvScrollViewmas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(lunBoView.mas_top);

            make.left.mas_equalTo(lunBoView.mas_left);

            make.right.mas_equalTo(lunBoView.mas_right);

            make.bottom.mas_equalTo(lunBoView.mas_bottom);

        }];

        

#pragma mark---排序資料---畫sortBtn

        //預設的狀態

        self.currentSortKind =0;

        EnumDetailDTO *model =self.enums[0];

        self.order = model.enumKey;

        //排序按鈕

        self.sortBtnBkg = [[UIViewalloc]init];

        self.sortBtnBkg.backgroundColor = [UIColorwhiteColor];

        [self.myCollectionViewaddSubview:self.sortBtnBkg];

        [self.sortBtnBkgmas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(self.myCollectionView.mas_left);

            make.top.mas_equalTo(lunBoView.mas_bottom);

            make.size.mas_equalTo(CGSizeMake(SCREEN_SIZE_WIDTH,43));

        }];

        self.sortBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];

        self.sortBtn.backgroundColor = [UIColorwhiteColor];

        [self.sortBtnsetTintColor:PINK_DARK_COLOR];

        [self.sortBtnsetTitle:model.enumValueforState:UIControlStateNormal];

        self.sortBtn.layer.cornerRadius = BUTTON_RADUIS;

        self.sortBtn.layer.borderWidth = 0.5;

        self.sortBtn.layer.borderColor = PINK_DARK_COLOR.CGColor;

        self.sortBtn.contentEdgeInsets =UIEdgeInsetsMake(0,10,0, 20);

        [self.sortBtnaddTarget:selfaction:@selector(chooseSortAction:)forControlEvents:UIControlEventTouchUpInside];

        [self.sortBtnBkgaddSubview:self.sortBtn];

        [self.sortBtnmas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(self.sortBtnBkg.mas_left).mas_equalTo(TEXT_EDGE_DISTANCE);

            make.centerY.mas_equalTo(self.sortBtnBkg.mas_centerY);

            make.size.mas_equalTo(CGSizeMake(SCREEN_SIZE_WIDTH/3,30));

        }];

        //後面的三角

        self.sortBtnImgv = [[UIImageViewalloc]init];

        [self.sortBtnaddSubview:self

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.