直播带货添加商品功能的方法

首先在viewdidload里面初始化整个页面,每一个模块:商品类别、商品标题、商品详情、规格、运费设置等都是一个子页面

  _backScroll = [[UIScrollView alloc]init];
    _backScroll.frame= CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-60);
    _backScroll.backgroundColor = RGB(250, 250, 250);
    [self.view addSubview:_backScroll];
    
    [self.view addSubview:self.bottomView];
    
    [self.backScroll addSubview:self.commodityClassView];
    [self.backScroll addSubview:self.titleView];
    [self.backScroll addSubview:self.contentView];
    [self.backScroll addSubview:self.standardsBackView];
    [self.backScroll addSubview:self.postageView];
    _backScroll.contentSize = CGSizeMake(_window_width, self.titleView.height+self.contentView.height+self.commodityClassView.height+self.standardsBackView.height+self.postageView.height+64+statusbarHeight+60);

2.选择商品类别

//商品类别
-(UIView *)commodityClassView{
    if (!_commodityClassView) {
        _commodityClassView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 55)];
        _commodityClassView.backgroundColor = [UIColor whiteColor];
        [_backScroll addSubview:_commodityClassView];
        
        UILabel*title = [[UILabel alloc]init];
        title.frame = CGRectMake(12, 55/2-10, 80, 20);
        title.centerY = _commodityClassView.centerY;
        title.font = [UIFont boldSystemFontOfSize:14];
        title.text = YZMsg(@"商品类别");
        title.textColor = [UIColor blackColor];
        [_commodityClassView addSubview:title];
        
        UIImageView *rightImg = [[UIImageView alloc]init];
        rightImg.frame = CGRectMake(_window_width-30, 0, 16, 16);
        rightImg.centerY = _commodityClassView.centerY;
        rightImg.image = [UIImage imageNamed:@"shop_right"];
        [_commodityClassView addSubview:rightImg];
        
        _classLb = [[UILabel alloc]init];
        _classLb.frame = CGRectMake(rightImg.left-150, 0, 150, 20);
        _classLb.centerY = _commodityClassView.centerY;
        _classLb.font = [UIFont systemFontOfSize:14];
        _classLb.text = YZMsg(@"请选择");
        _classLb.textColor = [UIColor grayColor];
        _classLb.textAlignment = NSTextAlignmentRight;
        [_commodityClassView addSubview:_classLb];
        
        UITapGestureRecognizer *classTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(classClick)];
        [_commodityClassView addGestureRecognizer:classTap];
    }
    return _commodityClassView;
}
-(void)classClick{
    SelCommodityClassVC *class = [[SelCommodityClassVC alloc]init];
    class.selClassEvent = ^(NSDictionary * _Nonnull firstDic, NSDictionary * _Nonnull twoDic, NSDictionary * _Nonnull threeDic) {
        one_classidStr = minstr([firstDic valueForKey:@"gc_id"]);
        two_classidStr = minstr([twoDic valueForKey:@"gc_id"]);
        three_classidStr =minstr([threeDic valueForKey:@"gc_id"]);
        _classLb.text = minstr([threeDic valueForKey:@"gc_name"]);
    };
    [[MXBADelegate sharedAppDelegate]pushViewController:class animated:YES];
}

3.添加商品标题、商品详情 由于可以添加视频、多个图片所以添加完成以后要重新刷新整个页面高度

//商品标题
-(CommodityTitleView *)titleView{
    YBWeakSelf;
    if (!_titleView) {
        _titleView = [[CommodityTitleView alloc]initWithFrame:CGRectMake(0, self.commodityClassView.bottom+5, _window_width, 170)];
        _titleView.delegate = self;
        _titleView.heightEvent = ^(CGFloat height) {
            titleViewHeight = height;
           weakSelf.titleView.size = CGSizeMake(_window_width, height);
            [weakSelf reloadUIHeight];
        };
    }
    return _titleView;
}
//商品详情
-(CommodityDetailView *)contentView{
    YBWeakSelf;

    if (!_contentView) {
        _contentView =[[CommodityDetailView alloc]initWithFrame:CGRectMake(0, self.titleView.bottom+5, _window_width, 330)];
        _contentView.delegate = self;
        _contentView.heightEvent = ^(CGFloat height) {
            detailViewHeight = height;
           weakSelf.contentView.size = CGSizeMake(_window_width, height);
            [weakSelf reloadUIHeight];
        };

    }
    return _contentView;
}

3.添加商品规格时每一个页面设置一个index 以便取页面数据、排序用

//添加规格
-(void)addStdClick{
    YBWeakSelf;
    StandardsView *standardsView =  [[StandardsView alloc]initWithFrame:CGRectMake(0, 40+standarsArr.count *240, _window_width, 240)];
    [_standardsBackView addSubview:standardsView];
    [standarsArr addObject:standardsView];
    standardsView.deleteBtn.hidden = NO;
    standardsView.index =standarsArr.count;
    standardsView.deleteEvent = ^(NSInteger tags) {
        NSLog(@"add--------:%ld",tags);
        for(id tmpView in [weakSelf.standardsBackView subviews])
        {
            if([tmpView isKindOfClass:[StandardsView class]]){
                StandardsView *selView = (StandardsView *)tmpView;
                if (selView.index == tags) {
                    [selView removeFromSuperview];
                    [standarsArr removeObjectAtIndex:tags-1];
                }
            }
        }
        for (int i = 0; i < standarsArr.count; i ++) {
            StandardsView *imgVVVV = standarsArr[i];
            imgVVVV.y = 40+240 * i;
            imgVVVV.index = i+1;
        }

        standardsHeight = 330+240 *(standarsArr.count-1);
        self.addStdBtn.frame = CGRectMake(0, 40+standarsArr.count *240+5, _window_width, 40);
        [self reloadUIHeight];

    };
    standardsHeight = 330+240 *(standarsArr.count-1);
    self.addStdBtn.frame = CGRectMake(0, 40+standarsArr.count *240+5, _window_width, 40);
    [self reloadUIHeight];
    
}

你可能感兴趣的:(技术类,python,html,vue,小程序,web)