123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- //
- // FKRecommendShopCell.m
- // FirstLink
- //
- // Created by jack on 16/4/9.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKRecoOfficalActivityCell.h"
- #import "FKRecommendViewModel.h"
- #import "SchemaManager.h"
- @interface FKRecoOfficalActivityCell ()
- @property (nonatomic, strong) UIImageView *imgView0;
- @property (nonatomic, strong) UIImageView *imgView1;
- @property (nonatomic, strong) NSArray<FKActivityItem *> *activityArray;
- @end
- @implementation FKRecoOfficalActivityCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self addAllSubViews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return self;
- }
- #pragma mark - Action
- - (IBAction)imageViewClickGesture:(UIGestureRecognizer *)sender {
- UIView *view = sender.view;
- if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
- if (view == self.imgView0) {
- [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:0];
- } else {
- [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:1];
- }
- } else {
- NSInteger startIdx = self.indexPath.row*2;
- if (view == self.imgView1) {
- startIdx++;
- }
- if (startIdx < self.activityArray.count) {
- FKActivityItem *item = self.activityArray[startIdx];
- [[SchemaManager sharedManager] parserURL:[NSURL URLWithString:item.targetUrl ? : @""] shouldCache:NO];
- }
- }
- }
- #pragma mark - Method
- + (CGFloat)marginWidth {
- if (IS_IPHONE_4 || IS_IPHONE_5) {
- return 5.0;
- } else if (IS_IPHONE_6) {
- return 6;
- }
- return 11;
- }
- + (CGFloat)imageViewWidth{
- return floor((UISCREENWIDTH - 3*[FKRecoOfficalActivityCell marginWidth])/2.0);
- }
- + (CGFloat)imageViewHeight{
- return floorf([FKRecoOfficalActivityCell imageViewWidth] * 160.0/305.0);
- }
- + (CGFloat)height {
- return ([FKRecoOfficalActivityCell imageViewHeight] + [FKRecoOfficalActivityCell marginWidth]);
- }
- #pragma mark - Layout
- - (void)addAllSubViews {
- CGSize size = CGSizeMake([FKRecoOfficalActivityCell imageViewWidth], [FKRecoOfficalActivityCell imageViewHeight]);
-
- [self.contentView addSubview:self.imgView0];
- [self.imgView0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset([FKRecoOfficalActivityCell marginWidth]);
- make.top.equalTo(self.contentView);
- make.size.mas_equalTo(size);
- }];
-
- [self.contentView addSubview:self.imgView1];
- [self.imgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.imgView0.mas_right).offset([FKRecoOfficalActivityCell marginWidth]);
- make.top.equalTo(self.contentView);
- make.size.mas_equalTo(size);
- }];
- }
- - (void)fk_configWithViewModel:(FKRecommendViewModel*)viewModel indexPath:(NSIndexPath *)indexPath {
- if ([viewModel isKindOfClass:[FKRecommendViewModel class]]) {
- self.indexPath = indexPath;
-
- NSInteger startIdx = (indexPath.row-1)*2;
-
- FKActivityItem *item = [viewModel.officalActivityArea dataItemAtIndex:startIdx];
- if (item) {
- [self.imgView0 setImageWithURL:item.picUrl
- placeholderImage:nil
- width:[FKRecoOfficalActivityCell imageViewWidth]
- height:[FKRecoOfficalActivityCell imageViewHeight]];
- }
-
- item = [viewModel.officalActivityArea dataItemAtIndex:++startIdx];
- if (item) {
- [self.imgView1 setImageWithURL:item.picUrl
- placeholderImage:nil
- width:[FKRecoOfficalActivityCell imageViewWidth]
- height:[FKRecoOfficalActivityCell imageViewHeight]];
- }
- }
- }
- - (void)configWithActivityArray:(NSArray<FKActivityItem *> *)activityArray indexPath:(NSIndexPath *)indexPath {
- self.activityArray = activityArray;
- self.indexPath = indexPath;
-
- NSInteger startIdx = indexPath.row*2;
-
- FKActivityItem *item;
- if (startIdx < activityArray.count) {
- item = activityArray[startIdx];
- [self.imgView0 setImageWithURL:item.picUrl
- placeholderImage:nil
- width:[FKRecoOfficalActivityCell imageViewWidth]
- height:[FKRecoOfficalActivityCell imageViewHeight]];
- }
-
- if (++startIdx < activityArray.count) {
- item = activityArray[startIdx];
- [self.imgView1 setImageWithURL:item.picUrl
- placeholderImage:nil
- width:[FKRecoOfficalActivityCell imageViewWidth]
- height:[FKRecoOfficalActivityCell imageViewHeight]];
- }
- }
- #pragma mark - property
- - (UIImageView *)imgView0 {
- if (!_imgView0) {
- _imgView0 = [[UIImageView alloc] init];
- _imgView0.contentMode = UIViewContentModeScaleAspectFit;
- _imgView0.userInteractionEnabled = YES;
-
- [_imgView0 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(imageViewClickGesture:)]];
- }
- return _imgView0;
- }
- - (UIImageView *)imgView1 {
- if (!_imgView1) {
- _imgView1 = [[UIImageView alloc] init];
- _imgView1.contentMode = UIViewContentModeScaleAspectFit;
- _imgView1.userInteractionEnabled = YES;
-
- [_imgView1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(imageViewClickGesture:)]];
- }
- return _imgView1;
- }
- @end
|