// // FKProductRelativeCell.m // FirstLink // // Created by jack on 16/5/24. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProductRelativeCell.h" #import "FKProductRelativeView.h" #import "FKCircleDetailViewModel.h" #import "FKProDetailViewModel.h" @interface FKProductRelativeCell () @property (nonatomic, strong) FKProductRelativeView *leftRelativeView; @property (nonatomic, strong) FKProductRelativeView *rightRelativeView; @end @implementation FKProductRelativeCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){ [self addAllSubviews]; self.contentView.backgroundColor = [UIColor whiteColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.leftRelativeView]; [self.contentView addSubview:self.rightRelativeView]; [self.leftRelativeView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.top.bottom.equalTo(self.contentView); make.width.mas_equalTo([FKProductRelativeCell get_imageViewMargin]); }]; [self.rightRelativeView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(- 15); make.top.bottom.equalTo(self.contentView); make.width.mas_equalTo([FKProductRelativeCell get_imageViewMargin]); }]; } + (CGFloat)get_imageViewMargin{ return (UISCREENWIDTH - 30 - 10) / 2.0f; } + (CGFloat)fk_getCellHeight{ return [self get_imageViewMargin] + 60.0f; } + (CGFloat)cellHeight{ return [self fk_getCellHeight]; } - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]){ FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; FKProductRelativeItem *leftModel = [detailModel relativeItemAtIndex:indexPath.row * 2]; FKProductRelativeItem *rightModel = [detailModel relativeItemAtIndex:indexPath.row * 2 + 1]; self.leftRelativeView.tag = indexPath.row * 2; self.rightRelativeView.tag = indexPath.row * 2 + 1; [self.leftRelativeView configWithRelativeItem:leftModel]; [self.rightRelativeView configWithRelativeItem:rightModel]; } if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]){ FKProductRelativeItem *leftModel = [viewModel relativeItemAtIndex:indexPath.row * 2]; FKProductRelativeItem *rightModel = [viewModel relativeItemAtIndex:indexPath.row * 2 + 1]; self.leftRelativeView.tag = indexPath.row * 2; self.rightRelativeView.tag = indexPath.row * 2 + 1; [self.leftRelativeView configWithRelativeItem:leftModel]; [self.rightRelativeView configWithRelativeItem:rightModel]; } } - (void)clickRelativeView:(UIGestureRecognizer *)gesture{ NSInteger index = gesture.view.tag; if (self.clickRelative){ self.clickRelative(index); } } #pragma mark - property - (FKProductRelativeView *)leftRelativeView{ if (_leftRelativeView == nil) { _leftRelativeView = [[FKProductRelativeView alloc]init]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRelativeView:)]; [_leftRelativeView addGestureRecognizer:tap]; } return _leftRelativeView; } - (FKProductRelativeView *)rightRelativeView{ if (_rightRelativeView == nil) { _rightRelativeView = [[FKProductRelativeView alloc]init]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRelativeView:)]; [_rightRelativeView addGestureRecognizer:tap]; } return _rightRelativeView; } @end