Commit 8e97e9e981a20407578da1d78ba18476a7fcfa50

Authored by 王军波
1 parent d5520be1

搜索栏代码重构,从组头中提取出来

LiveVideoCloud.xcodeproj/project.pbxproj
... ... @@ -202,6 +202,7 @@
202 202 D217A24A1E7B76C7003B44CB /* PresentView.m in Sources */ = {isa = PBXBuildFile; fileRef = D217A2471E7B76C7003B44CB /* PresentView.m */; };
203 203 D217A24B1E7B76C7003B44CB /* PresentViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D217A2491E7B76C7003B44CB /* PresentViewCell.m */; };
204 204 D217A24E1E7B77C7003B44CB /* ComboCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D217A24D1E7B77C7003B44CB /* ComboCell.m */; };
  205 + D219E86B1EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D219E86A1EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.m */; };
205 206 D224B1971E826ED800CC61D0 /* ChatBarrageAnimAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D224B1961E826ED800CC61D0 /* ChatBarrageAnimAction.m */; };
206 207 D22830F11E778C0F00627701 /* LiveBaseView.m in Sources */ = {isa = PBXBuildFile; fileRef = D22830F01E778C0F00627701 /* LiveBaseView.m */; };
207 208 D22830FC1E77C2D900627701 /* BottomToolView.m in Sources */ = {isa = PBXBuildFile; fileRef = D22830FB1E77C2D900627701 /* BottomToolView.m */; };
... ... @@ -714,6 +715,8 @@
714 715 D217A2491E7B76C7003B44CB /* PresentViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PresentViewCell.m; sourceTree = "<group>"; };
715 716 D217A24C1E7B77C7003B44CB /* ComboCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ComboCell.h; path = Present/ComboCell.h; sourceTree = "<group>"; };
716 717 D217A24D1E7B77C7003B44CB /* ComboCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ComboCell.m; path = Present/ComboCell.m; sourceTree = "<group>"; };
  718 + D219E8691EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LVCBigHorizontalCollectionViewCell.h; sourceTree = "<group>"; };
  719 + D219E86A1EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LVCBigHorizontalCollectionViewCell.m; sourceTree = "<group>"; };
717 720 D224B1951E826ED800CC61D0 /* ChatBarrageAnimAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatBarrageAnimAction.h; sourceTree = "<group>"; };
718 721 D224B1961E826ED800CC61D0 /* ChatBarrageAnimAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatBarrageAnimAction.m; sourceTree = "<group>"; };
719 722 D22830EF1E778C0F00627701 /* LiveBaseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LiveBaseView.h; sourceTree = "<group>"; };
... ... @@ -1783,6 +1786,8 @@
1783 1786 D23BBDC61EF8FBD1002FE0B8 /* LVCSectionHeaderCollectionReusableView.m */,
1784 1787 D23BBDC21EF8FB99002FE0B8 /* LVCMainHorizontalCollectionViewCell.h */,
1785 1788 D23BBDC31EF8FB99002FE0B8 /* LVCMainHorizontalCollectionViewCell.m */,
  1789 + D219E8691EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.h */,
  1790 + D219E86A1EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.m */,
1786 1791 D24F40931EFB965A00833738 /* JBSearchView.h */,
1787 1792 D24F40941EFB965A00833738 /* JBSearchView.m */,
1788 1793 D24CFC1E1EFA092300AA6ADB /* JBBannerView.h */,
... ... @@ -2425,6 +2430,7 @@
2425 2430 D233EE721EEA88EF00674ED5 /* LVCHomePageViewController.m in Sources */,
2426 2431 D236967E1E7F9E4100E4BF71 /* GiftPayButton.m in Sources */,
2427 2432 4BD8560A1EBACD530082061D /* UIWebView+AFNetworking.m in Sources */,
  2433 + D219E86B1EFD04A700650F38 /* LVCBigHorizontalCollectionViewCell.m in Sources */,
2428 2434 4B45CE831EB86A590079AFB7 /* LVCMineModel.m in Sources */,
2429 2435 4B45CE791EB86A590079AFB7 /* MineAboutUsController.m in Sources */,
2430 2436 81A483081E88B6140097A80A /* UIView+ViewController.m in Sources */,
... ...
LiveVideoCloud/Classes/Sections/HomePageSections/LVCBigHorizontalCollectionViewCell.h 0 → 100644
  1 +//
  2 +// LVCBigHorizontalCollectionViewCell.h
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by cnliveJunBo on 17/6/23.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface LVCBigHorizontalCollectionViewCell : UICollectionViewCell
  12 +
  13 +@property (nonatomic, strong)ProgramModel *model;
  14 +@property (nonatomic, strong)ProgramModel *liveModel;
  15 +
  16 +@end
... ...
LiveVideoCloud/Classes/Sections/HomePageSections/LVCBigHorizontalCollectionViewCell.m 0 → 100644
  1 +//
  2 +// LVCBigHorizontalCollectionViewCell.m
  3 +// LiveVideoCloud
  4 +//
  5 +// Created by cnliveJunBo on 17/6/23.
  6 +// Copyright © 2017年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "LVCBigHorizontalCollectionViewCell.h"
  10 +
  11 +@interface LVCBigHorizontalCollectionViewCell() {
  12 +
  13 + CGFloat _x;
  14 +}
  15 +
  16 +@property (nonatomic, strong) UIImageView *imageView;
  17 +@property (nonatomic, strong) UILabel *title;
  18 +@property (nonatomic, strong) UILabel *detail;
  19 +@property (nonatomic, strong) UIImageView *typeImage; //节目类型角标
  20 +
  21 +@end
  22 +
  23 +@implementation LVCBigHorizontalCollectionViewCell
  24 +
  25 +- (instancetype)initWithFrame:(CGRect)frame
  26 +{
  27 + self = [super initWithFrame:frame];
  28 + if (self) {
  29 + if ([UIDevice currentDevice].systemVersion.floatValue >= 10) {
  30 + _x = 0;
  31 + } else {
  32 + _x = 10;
  33 + }
  34 + [self.contentView addSubview:self.imageView];
  35 + [self.contentView addSubview:self.title];
  36 + [self.contentView addSubview:self.detail];
  37 + [self.imageView addSubview:self.typeImage];
  38 + }
  39 + return self;
  40 +}
  41 +
  42 +- (void)setModel:(ProgramModel *)model {
  43 +
  44 + if (_model != model) {
  45 + _model = model;
  46 + }
  47 +}
  48 +
  49 +- (void)setLiveModel:(ProgramModel *)liveModel {
  50 +
  51 + if (_liveModel != liveModel) {
  52 + _liveModel = liveModel;
  53 + }
  54 +}
  55 +
  56 +#pragma mark - GetMethod !!!!!!!!!!!!!!!!!!
  57 +- (UIImageView *)imageView
  58 +{
  59 + if (!_imageView) {
  60 + _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(_x, 0, self.contentView.width-20, (self.contentView.width-20)/2)];
  61 + _imageView.backgroundColor = [UIColor grayColor];
  62 + }
  63 + return _imageView;
  64 +}
  65 +
  66 +- (UILabel *)title
  67 +{
  68 + if (!_title) {
  69 + _title = [[UILabel alloc] initWithFrame:CGRectMake(_x, self.imageView.bottom+7, self.contentView.width-10, 12)];
  70 + _title.font = [UIFont systemFontOfSize:14];
  71 + _title.textColor = [UIColor blackColorCNLive];
  72 + }
  73 + return _title;
  74 +}
  75 +
  76 +- (UILabel *)detail
  77 +{
  78 + if (!_detail) {
  79 + _detail = [[UILabel alloc] initWithFrame:CGRectMake(_x, self.title.bottom+7, self.contentView.width-10, 11)];
  80 + _detail.font = [UIFont systemFontOfSize:12];
  81 + _detail.textColor = [UIColor grayColorCNLive];
  82 + }
  83 + return _detail;
  84 +}
  85 +
  86 +- (UIImageView *)typeImage
  87 +{
  88 + if (!_typeImage) {
  89 + _typeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 39, 39)];
  90 + }
  91 + return _typeImage;
  92 +}
  93 +
  94 +@end
... ...
LiveVideoCloud/Classes/Sections/HomePageSections/LVCChannelPagingView.m
... ... @@ -10,6 +10,7 @@
10 10 #import "LVCMainHeaderCollectionReusableView.h"
11 11 #import "LVCSectionHeaderCollectionReusableView.h"
12 12 #import "LVCMainHorizontalCollectionViewCell.h"
  13 +#import "JBSearchView.h"
13 14  
14 15 static NSString *mainHeaderId = @"mainHeader";
15 16 static NSString *SectionHeaderId = @"SectionHeader";
... ... @@ -22,11 +23,14 @@ static NSString *MainHorizontalCellId = @&quot;MainHorizontalCell&quot;;
22 23 NSMutableArray *_banners;
23 24 NSMutableArray *_marquees;
24 25 NSMutableArray *_channels;
  26 + LVCMainHeaderCollectionReusableView *_mainHeader;
  27 + CGFloat _collectionOffsetY;
25 28 }
26 29  
27 30 @property (nonatomic, strong)UICollectionView *collectionView;
28   -@property (nonatomic, strong)UIView *searchBackground;
29   -@property (nonatomic, strong)UIButton *searchBtn;
  31 +//@property (nonatomic, strong)UIView *searchBackground;
  32 +@property (nonatomic, strong)JBSearchView *searchView;
  33 +//@property (nonatomic, strong)UIButton *searchBtn;
30 34 @property (nonatomic, strong)UIView *searchLine;
31 35 @property (nonatomic, strong)UILabel *searchHotLab;
32 36  
... ... @@ -91,7 +95,7 @@ static NSString *MainHorizontalCellId = @&quot;MainHorizontalCell&quot;;
91 95 // 搜索旁的分类
92 96 } else {
93 97  
94   - self.searchBtn.width = KScreenWidth - 20;
  98 +// self.searchBtn.width = KScreenWidth - 20;
95 99 }
96 100  
97 101 if (responseObject[@"banner"] && [responseObject[@"banner"] isKindOfClass:[NSArray class]]) {
... ... @@ -146,7 +150,42 @@ static NSString *MainHorizontalCellId = @&quot;MainHorizontalCell&quot;;
146 150 #pragma mark - UICollectionViewDelegate !!!!!!!!!!!!!!!!!!!!!!!!!
147 151 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
148 152  
149   -
  153 + if (_hasSearchBox) {
  154 +
  155 + if (scrollView == self.collectionView) {
  156 +
  157 + if (scrollView.contentOffset.y <= 0) {
  158 +
  159 + self.searchView.y = 0;
  160 + if (_channels.count > 0) {
  161 + [_mainHeader addSubview:self.searchView];
  162 + } else {
  163 + [self.collectionView addSubview:self.searchView];
  164 + }
  165 + _collectionOffsetY = scrollView.contentOffset.y;
  166 + } else {
  167 +
  168 + if (scrollView.contentOffset.y >= 45) {
  169 + if (self.searchView.superview != self) {
  170 + self.searchView.y = -45;
  171 + [self.searchView addSubview:self.searchLine];
  172 + [self addSubview:self.searchView];
  173 + }
  174 + }
  175 + if (scrollView.contentOffset.y-_collectionOffsetY > 0) {
  176 + _collectionOffsetY = scrollView.contentOffset.y;
  177 + [UIView animateWithDuration:0.2 animations:^{
  178 + self.searchView.y = -45;
  179 + }];
  180 + } else {
  181 + _collectionOffsetY = scrollView.contentOffset.y;
  182 + [UIView animateWithDuration:0.2 animations:^{
  183 + self.searchView.y = 0;
  184 + }];
  185 + }
  186 + }
  187 + }
  188 + }
150 189 }
151 190  
152 191 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
... ... @@ -175,9 +214,12 @@ static NSString *MainHorizontalCellId = @&quot;MainHorizontalCell&quot;;
175 214 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
176 215  
177 216 if (indexPath.section == 0) {
178   - LVCMainHeaderCollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:mainHeaderId forIndexPath:indexPath];
179   - view.backgroundColor = [UIColor redColor];
180   - return view;
  217 + _mainHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:mainHeaderId forIndexPath:indexPath];
  218 + _mainHeader.backgroundColor = [UIColor redColor];
  219 + if (!self.searchView.superview) {
  220 + [_mainHeader addSubview:self.searchView];
  221 + }
  222 + return _mainHeader;
181 223 } else {
182 224 LVCSectionHeaderCollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:SectionHeaderId forIndexPath:indexPath];
183 225 view.backgroundColor = [UIColor yellowColor];
... ... @@ -236,33 +278,21 @@ static NSString *MainHorizontalCellId = @&quot;MainHorizontalCell&quot;;
236 278 return _collectionView;
237 279 }
238 280  
239   -- (UIView *)searchBackground {
  281 +- (JBSearchView *)searchView {
240 282  
241   - if (!_searchBackground) {
242   - _searchBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 45)];
243   - _searchBackground.backgroundColor = [UIColor backgroundColor];
244   - [_searchBackground addSubview:self.searchBtn];
245   - }
246   - return _searchBackground;
247   -}
248   -
249   -- (UIButton *)searchBtn {
250   -
251   - if (!_searchBtn) {
  283 + if (!_searchView) {
  284 + _searchView = [[JBSearchView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 45)];
  285 + _searchView.backgroundColor = [UIColor backgroundColor];
  286 +
  287 + NSMutableArray *arrayM = [[NSMutableArray alloc] init];
  288 + NSDictionary *dict1 = @{@"name":@"liveShow"};
  289 + [arrayM addObject:dict1];
  290 + NSDictionary *dict2 = @{@"name":@"全部"};
  291 + [arrayM addObject:dict2];
  292 + _searchView.sortArray = arrayM;
252 293  
253   - _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
254   - _searchBtn.frame = CGRectMake(10, 6, KScreenWidth-20, 33);
255   - [_searchBtn setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
256   - [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
257   - [_searchBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
258   - [_searchBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -5, 0, 0)];
259   - _searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
260   - _searchBtn.backgroundColor = [UIColor whiteColor];
261   - _searchBtn.layer.cornerRadius = 16;
262   - _searchBtn.layer.masksToBounds = YES;
263   - [_searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
264 294 }
265   - return _searchBtn;
  295 + return _searchView;
266 296 }
267 297  
268 298 - (UIView *)searchLine {
... ...
LiveVideoCloud/Classes/Sections/HomePageSections/LVCMainHeaderCollectionReusableView.m
... ... @@ -7,7 +7,6 @@
7 7 //
8 8  
9 9 #import "LVCMainHeaderCollectionReusableView.h"
10   -#import "JBSearchView.h"
11 10 #import "JBBannerView.h"
12 11 #import "JBAutoRollTableView.h"
13 12  
... ... @@ -15,7 +14,6 @@
15 14  
16 15 @property (nonatomic, strong) JBBannerView *bannerView;
17 16 @property (nonatomic, strong) JBAutoRollTableView *rollTableView;
18   -@property (nonatomic, strong) JBSearchView *searchView;
19 17  
20 18 @end
21 19  
... ... @@ -25,7 +23,7 @@
25 23 {
26 24 self = [super initWithFrame:frame];
27 25 if (self) {
28   - [self addSubview:self.searchView];
  26 +// [self addSubview:self.searchView];
29 27 [self addSubview:self.bannerView];
30 28 [self addSubview:self.rollTableView];
31 29 }
... ... @@ -33,23 +31,6 @@
33 31 }
34 32  
35 33 #pragma mark - GetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36   -- (JBSearchView *)searchView {
37   -
38   - if (!_searchView) {
39   - _searchView = [[JBSearchView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 45)];
40   - _searchView.backgroundColor = [UIColor backgroundColor];
41   -
42   - NSMutableArray *arrayM = [[NSMutableArray alloc] init];
43   - NSDictionary *dict1 = @{@"name":@"liveShow"};
44   - [arrayM addObject:dict1];
45   - NSDictionary *dict2 = @{@"name":@"全部"};
46   - [arrayM addObject:dict2];
47   - _searchView.sortArray = arrayM;
48   -
49   - }
50   - return _searchView;
51   -}
52   -
53 34 - (JBBannerView *)bannerView {
54 35  
55 36 if (!_bannerView) {
... ...