No Description

FKProductRelativeCell.m 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // FKProductRelativeCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/5/24.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProductRelativeCell.h"
  9. #import "FKProductRelativeView.h"
  10. #import "FKCircleDetailViewModel.h"
  11. #import "FKProDetailViewModel.h"
  12. @interface FKProductRelativeCell ()
  13. @property (nonatomic, strong) FKProductRelativeView *leftRelativeView;
  14. @property (nonatomic, strong) FKProductRelativeView *rightRelativeView;
  15. @end
  16. @implementation FKProductRelativeCell
  17. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  18. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
  19. [self addAllSubviews];
  20. self.contentView.backgroundColor = [UIColor whiteColor];
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. }
  23. return self;
  24. }
  25. - (void)addAllSubviews{
  26. [self.contentView addSubview:self.leftRelativeView];
  27. [self.contentView addSubview:self.rightRelativeView];
  28. [self.leftRelativeView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.equalTo(self.contentView).offset(15);
  30. make.top.bottom.equalTo(self.contentView);
  31. make.width.mas_equalTo([FKProductRelativeCell get_imageViewMargin]);
  32. }];
  33. [self.rightRelativeView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.right.equalTo(self.contentView).offset(- 15);
  35. make.top.bottom.equalTo(self.contentView);
  36. make.width.mas_equalTo([FKProductRelativeCell get_imageViewMargin]);
  37. }];
  38. }
  39. + (CGFloat)get_imageViewMargin{
  40. return (UISCREENWIDTH - 30 - 10) / 2.0f;
  41. }
  42. + (CGFloat)fk_getCellHeight{
  43. return [self get_imageViewMargin] + 60.0f;
  44. }
  45. + (CGFloat)cellHeight{
  46. return [self fk_getCellHeight];
  47. }
  48. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  49. if ([viewModel isKindOfClass:[FKProDetailViewModel class]]){
  50. FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
  51. FKProductRelativeItem *leftModel = [detailModel relativeItemAtIndex:indexPath.row * 2];
  52. FKProductRelativeItem *rightModel = [detailModel relativeItemAtIndex:indexPath.row * 2 + 1];
  53. self.leftRelativeView.tag = indexPath.row * 2;
  54. self.rightRelativeView.tag = indexPath.row * 2 + 1;
  55. [self.leftRelativeView configWithRelativeItem:leftModel];
  56. [self.rightRelativeView configWithRelativeItem:rightModel];
  57. }
  58. if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]){
  59. FKProductRelativeItem *leftModel = [viewModel relativeItemAtIndex:indexPath.row * 2];
  60. FKProductRelativeItem *rightModel = [viewModel relativeItemAtIndex:indexPath.row * 2 + 1];
  61. self.leftRelativeView.tag = indexPath.row * 2;
  62. self.rightRelativeView.tag = indexPath.row * 2 + 1;
  63. [self.leftRelativeView configWithRelativeItem:leftModel];
  64. [self.rightRelativeView configWithRelativeItem:rightModel];
  65. }
  66. }
  67. - (void)clickRelativeView:(UIGestureRecognizer *)gesture{
  68. NSInteger index = gesture.view.tag;
  69. if (self.clickRelative){
  70. self.clickRelative(index);
  71. }
  72. }
  73. #pragma mark - property
  74. - (FKProductRelativeView *)leftRelativeView{
  75. if (_leftRelativeView == nil) {
  76. _leftRelativeView = [[FKProductRelativeView alloc]init];
  77. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRelativeView:)];
  78. [_leftRelativeView addGestureRecognizer:tap];
  79. }
  80. return _leftRelativeView;
  81. }
  82. - (FKProductRelativeView *)rightRelativeView{
  83. if (_rightRelativeView == nil) {
  84. _rightRelativeView = [[FKProductRelativeView alloc]init];
  85. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRelativeView:)];
  86. [_rightRelativeView addGestureRecognizer:tap];
  87. }
  88. return _rightRelativeView;
  89. }
  90. @end