1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// KWMHotSalesHeader.m
// iCemarose
//
// Created by HouWeiBin on 2017/7/10.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMHotSalesHeader.h"
#import "KWMProductBannerItemView.h"
#import "UIImageView+WebCache.h"
#import "KWMNewHomeCell.h"
@interface KWMHotSalesHeader()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic,weak) IBOutlet UIView *vView;
@property (nonatomic,weak) IBOutlet KWMBannerView *bannerView;
@property (nonatomic,weak) IBOutlet UICollectionView *singleShowView;
@property (nonatomic,weak) IBOutlet NSLayoutConstraint *heightBannerView;
@property (nonatomic,weak) IBOutlet NSLayoutConstraint *heightSingleShowView;
@end
@implementation KWMHotSalesHeader
+(NSString *)kwmTag{
return @"KWMHotSalesHeader";
}
- (id)init{
if (self=[super init]){
[self addView];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self addView];
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame{
if (self =[super initWithFrame:frame]) {
[self addView];
}
return self;
}
-(void)addView{
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class])
owner:self
options:nil];
self.vView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vView];
[self initView];
}
-(NSInteger)actrualHeight{
NSInteger height = 60 + self.heightSingleShowView.constant + self.heightBannerView.constant;
return height;
}
-(void)initView{
UINib *nib = [UINib nibWithNibName:@"KWMNewHomeCell" bundle:nil];
[self.singleShowView registerNib:nib forCellWithReuseIdentifier:@"KWMNewHomeCell"];
// [self.singleShowView registerNib:nib forCellReuseIdentifier:@"KWMNewHomeCell"];
// [self.singleShowView registerNib:[[[NSBundle mainBundle]loadNibNamed:@"KWMNewHomeCell" owner:self options:nil] firstObject] forCellReuseIdentifier:@"KWMNewHomeCell"];
self.singleShowView.delegate = self;
self.singleShowView.dataSource = self;
// self.singleShowView.collectionViewLayout.collectionViewContentSize = CGSizeMake(UI_SCREEN_WIDTH - 16, UI_SCREEN_WIDTH + 58);
// self.singleShowView.collectionViewLayout = [UICollectionViewLayout alloc]
self.bannerView.delegate = self;
self.heightBannerView.constant = 0;
self.heightSingleShowView.constant = 0;
}
-(void)startBannerTimer{
[self.bannerView addTimer];
}
-(void)endBannerTimer{
[self.bannerView removeTimer];
}
-(void)setBannerArray:(NSArray *)bannerArray{
_bannerArray = bannerArray;
if(bannerArray && bannerArray.count > 0){
self.heightBannerView.constant = 190;
[self.bannerView reloadData];
}else{
self.heightBannerView.constant = 0;
}
}
-(void)setSingleShowArray:(NSArray *)singleShowArray{
_singleShowArray = singleShowArray ? singleShowArray : [NSArray array];
NSInteger itemWidth = UI_SCREEN_WIDTH - 16;
NSInteger itemHeight = UI_SCREEN_WIDTH + 58;
// for(int i=0;i<singleShowArray.count;i++){
// BUYProduct *product = [singleShowArray objectAtIndex:i];
// NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"KWMNewHomeCell" owner:self options:nil];
// KWMNewHomeCell *homeCell = [nib objectAtIndex:0];
// homeCell.frame = CGRectMake(8, itemHeight*i, itemWidth, itemHeight);
// homeCell.singleShow = YES;
// homeCell.tag = i;
// homeCell.product = product;
//
// [self.singleShowView addSubview:homeCell];
// }
self.heightSingleShowView.constant = itemHeight*singleShowArray.count;
}
#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.singleShowArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
KWMNewHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KWMNewHomeCell" forIndexPath:indexPath];
cell.singleShow = YES;
cell.product = self.singleShowArray[indexPath.item];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(UI_SCREEN_WIDTH - 16, UI_SCREEN_WIDTH + 58);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self.delegate kwm_onClickProduct:self.singleShowArray[indexPath.item]];
}
#pragma mark - KWMBannerViewDelegate
-(UIView *)bannerView:(KWMBannerView *)bannerView reusingView:(UIView *)reusingView pageAtIndex:(NSInteger)index{
UIView *itemView = reusingView?reusingView:nil;
KWMProductBannerItemView *productBannerItem = nil;
if(!itemView){
productBannerItem = [[KWMProductBannerItemView alloc]initWithFrame:CGRectMake(0, 0, bannerView.frame.size.width, bannerView.frame.size.height)];
}else{
productBannerItem = (KWMProductBannerItemView *)itemView;
}
itemView = productBannerItem;
return itemView;
}
-(NSInteger)numberOfPagesForBanner:(KWMBannerView *)bannerView{
return self.bannerArray?self.bannerArray.count:0;
}
-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
BUYProduct *product = [self.bannerArray objectAtIndex:index];
if(self.delegate){
[self.delegate kwm_onClickProduct:product];
}
}
@end