No Description

FKRecoOfficalActivityCell.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // FKRecommendShopCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/4/9.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKRecoOfficalActivityCell.h"
  9. #import "FKRecommendViewModel.h"
  10. #import "SchemaManager.h"
  11. @interface FKRecoOfficalActivityCell ()
  12. @property (nonatomic, strong) UIImageView *imgView0;
  13. @property (nonatomic, strong) UIImageView *imgView1;
  14. @property (nonatomic, strong) NSArray<FKActivityItem *> *activityArray;
  15. @end
  16. @implementation FKRecoOfficalActivityCell
  17. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  18. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. if (self) {
  20. [self addAllSubViews];
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. }
  23. return self;
  24. }
  25. #pragma mark - Action
  26. - (IBAction)imageViewClickGesture:(UIGestureRecognizer *)sender {
  27. UIView *view = sender.view;
  28. if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
  29. if (view == self.imgView0) {
  30. [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:0];
  31. } else {
  32. [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:1];
  33. }
  34. } else {
  35. NSInteger startIdx = self.indexPath.row*2;
  36. if (view == self.imgView1) {
  37. startIdx++;
  38. }
  39. if (startIdx < self.activityArray.count) {
  40. FKActivityItem *item = self.activityArray[startIdx];
  41. [[SchemaManager sharedManager] parserURL:[NSURL URLWithString:item.targetUrl ? : @""] shouldCache:NO];
  42. }
  43. }
  44. }
  45. #pragma mark - Method
  46. + (CGFloat)marginWidth {
  47. if (IS_IPHONE_4 || IS_IPHONE_5) {
  48. return 5.0;
  49. } else if (IS_IPHONE_6) {
  50. return 6;
  51. }
  52. return 11;
  53. }
  54. + (CGFloat)imageViewWidth{
  55. return floor((UISCREENWIDTH - 3*[FKRecoOfficalActivityCell marginWidth])/2.0);
  56. }
  57. + (CGFloat)imageViewHeight{
  58. return floorf([FKRecoOfficalActivityCell imageViewWidth] * 160.0/305.0);
  59. }
  60. + (CGFloat)height {
  61. return ([FKRecoOfficalActivityCell imageViewHeight] + [FKRecoOfficalActivityCell marginWidth]);
  62. }
  63. #pragma mark - Layout
  64. - (void)addAllSubViews {
  65. CGSize size = CGSizeMake([FKRecoOfficalActivityCell imageViewWidth], [FKRecoOfficalActivityCell imageViewHeight]);
  66. [self.contentView addSubview:self.imgView0];
  67. [self.imgView0 mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.equalTo(self.contentView).offset([FKRecoOfficalActivityCell marginWidth]);
  69. make.top.equalTo(self.contentView);
  70. make.size.mas_equalTo(size);
  71. }];
  72. [self.contentView addSubview:self.imgView1];
  73. [self.imgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.equalTo(self.imgView0.mas_right).offset([FKRecoOfficalActivityCell marginWidth]);
  75. make.top.equalTo(self.contentView);
  76. make.size.mas_equalTo(size);
  77. }];
  78. }
  79. - (void)fk_configWithViewModel:(FKRecommendViewModel*)viewModel indexPath:(NSIndexPath *)indexPath {
  80. if ([viewModel isKindOfClass:[FKRecommendViewModel class]]) {
  81. self.indexPath = indexPath;
  82. NSInteger startIdx = (indexPath.row-1)*2;
  83. FKActivityItem *item = [viewModel.officalActivityArea dataItemAtIndex:startIdx];
  84. if (item) {
  85. [self.imgView0 setImageWithURL:item.picUrl
  86. placeholderImage:nil
  87. width:[FKRecoOfficalActivityCell imageViewWidth]
  88. height:[FKRecoOfficalActivityCell imageViewHeight]];
  89. }
  90. item = [viewModel.officalActivityArea dataItemAtIndex:++startIdx];
  91. if (item) {
  92. [self.imgView1 setImageWithURL:item.picUrl
  93. placeholderImage:nil
  94. width:[FKRecoOfficalActivityCell imageViewWidth]
  95. height:[FKRecoOfficalActivityCell imageViewHeight]];
  96. }
  97. }
  98. }
  99. - (void)configWithActivityArray:(NSArray<FKActivityItem *> *)activityArray indexPath:(NSIndexPath *)indexPath {
  100. self.activityArray = activityArray;
  101. self.indexPath = indexPath;
  102. NSInteger startIdx = indexPath.row*2;
  103. FKActivityItem *item;
  104. if (startIdx < activityArray.count) {
  105. item = activityArray[startIdx];
  106. [self.imgView0 setImageWithURL:item.picUrl
  107. placeholderImage:nil
  108. width:[FKRecoOfficalActivityCell imageViewWidth]
  109. height:[FKRecoOfficalActivityCell imageViewHeight]];
  110. }
  111. if (++startIdx < activityArray.count) {
  112. item = activityArray[startIdx];
  113. [self.imgView1 setImageWithURL:item.picUrl
  114. placeholderImage:nil
  115. width:[FKRecoOfficalActivityCell imageViewWidth]
  116. height:[FKRecoOfficalActivityCell imageViewHeight]];
  117. }
  118. }
  119. #pragma mark - property
  120. - (UIImageView *)imgView0 {
  121. if (!_imgView0) {
  122. _imgView0 = [[UIImageView alloc] init];
  123. _imgView0.contentMode = UIViewContentModeScaleAspectFit;
  124. _imgView0.userInteractionEnabled = YES;
  125. [_imgView0 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
  126. action:@selector(imageViewClickGesture:)]];
  127. }
  128. return _imgView0;
  129. }
  130. - (UIImageView *)imgView1 {
  131. if (!_imgView1) {
  132. _imgView1 = [[UIImageView alloc] init];
  133. _imgView1.contentMode = UIViewContentModeScaleAspectFit;
  134. _imgView1.userInteractionEnabled = YES;
  135. [_imgView1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
  136. action:@selector(imageViewClickGesture:)]];
  137. }
  138. return _imgView1;
  139. }
  140. @end