Commit e5d951c632307565ebdaf5334411a25aa17dbcb4

Authored by 王军波
1 parent 06536287

刷新

LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Controller/HomeViewController.m
@@ -171,7 +171,11 @@ @@ -171,7 +171,11 @@
171 LVCUGCLiveListView *liveListView = (LVCUGCLiveListView *)[pagingScrollView pageViewByIndex:index]; 171 LVCUGCLiveListView *liveListView = (LVCUGCLiveListView *)[pagingScrollView pageViewByIndex:index];
172 if (!liveListView) { 172 if (!liveListView) {
173 liveListView = [[LVCUGCLiveListView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 114)]; 173 liveListView = [[LVCUGCLiveListView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 114)];
  174 + } else {
  175 + [liveListView isNeedToRefresh];
  176 + [liveListView stopAutoRefresh];
174 } 177 }
  178 + liveListView.scrollToTop = YES;
175 return liveListView; 179 return liveListView;
176 } 180 }
177 return nil; 181 return nil;
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLiveListView.h
@@ -10,4 +10,9 @@ @@ -10,4 +10,9 @@
10 10
11 @interface LVCUGCLiveListView : UIView 11 @interface LVCUGCLiveListView : UIView
12 12
  13 +@property (nonatomic, assign)BOOL scrollToTop;
  14 +
  15 +- (void)isNeedToRefresh;
  16 +- (void)stopAutoRefresh;
  17 +
13 @end 18 @end
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLiveListView.m
@@ -18,6 +18,9 @@ static NSString *cellId = @"cellId"; @@ -18,6 +18,9 @@ static NSString *cellId = @"cellId";
18 @interface LVCUGCLiveListView()<UICollectionViewDelegate, UICollectionViewDataSource> { 18 @interface LVCUGCLiveListView()<UICollectionViewDelegate, UICollectionViewDataSource> {
19 19
20 NSMutableArray *_arrayM; 20 NSMutableArray *_arrayM;
  21 + long long _timestamp;
  22 + NSTimer *_autoRefreshTimer;
  23 + CGFloat _refreshTime;
21 } 24 }
22 25
23 @property (nonatomic, strong) UICollectionView *collectionView; 26 @property (nonatomic, strong) UICollectionView *collectionView;
@@ -36,9 +39,9 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -36,9 +39,9 @@ static NSString *cellId = @&quot;cellId&quot;;
36 39
37 _arrayM = [[NSMutableArray alloc] init]; 40 _arrayM = [[NSMutableArray alloc] init];
38 41
39 - [self loadData];  
40 -  
41 [self addSubview:self.collectionView]; 42 [self addSubview:self.collectionView];
  43 +
  44 + [self.collectionView.header beginRefreshing];
42 } 45 }
43 return self; 46 return self;
44 } 47 }
@@ -54,9 +57,16 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -54,9 +57,16 @@ static NSString *cellId = @&quot;cellId&quot;;
54 NSLog(@"data%@",data); 57 NSLog(@"data%@",data);
55 58
56 LVCUGCLiveListModel *model = [LVCUGCLiveListModel modelWithDic:data]; 59 LVCUGCLiveListModel *model = [LVCUGCLiveListModel modelWithDic:data];
57 -  
58 - NSLog(@"%@",model.activityList);  
59 _arrayM = model.activityList.mutableCopy; 60 _arrayM = model.activityList.mutableCopy;
  61 +
  62 + _timestamp = [[self timestamp] longLongValue];
  63 + if (_refreshTime != 0) {
  64 + [_autoRefreshTimer invalidate];
  65 + _autoRefreshTimer = nil;
  66 + _autoRefreshTimer = [NSTimer scheduledTimerWithTimeInterval:_refreshTime target:self selector:@selector(autoRefresh) userInfo:nil repeats:YES];
  67 + }
  68 + [self.collectionView.header endRefreshing];
  69 + [self.collectionView reloadData];
60 }]; 70 }];
61 71
62 } 72 }
@@ -95,18 +105,65 @@ static NSString *cellId = @&quot;cellId&quot;; @@ -95,18 +105,65 @@ static NSString *cellId = @&quot;cellId&quot;;
95 105
96 if (!_collectionView) { 106 if (!_collectionView) {
97 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 107 UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
98 - layout.minimumLineSpacing = 10; 108 + layout.minimumLineSpacing = 0;
99 layout.minimumInteritemSpacing = 0; 109 layout.minimumInteritemSpacing = 0;
100 - layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH + 100); 110 + layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH + 110);
101 _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout]; 111 _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
102 - _collectionView.backgroundColor = [UIColor lightGrayColor]; 112 + _collectionView.backgroundColor = [UIColor whiteColor];
103 _collectionView.showsHorizontalScrollIndicator = NO; 113 _collectionView.showsHorizontalScrollIndicator = NO;
104 _collectionView.dataSource = self; 114 _collectionView.dataSource = self;
105 _collectionView.delegate = self; 115 _collectionView.delegate = self;
  116 + _collectionView.scrollsToTop = YES;
106 [_collectionView registerClass:[LVCUGCLivePlayerCell class] forCellWithReuseIdentifier:cellId]; 117 [_collectionView registerClass:[LVCUGCLivePlayerCell class] forCellWithReuseIdentifier:cellId];
  118 + _collectionView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)];
107 } 119 }
108 return _collectionView; 120 return _collectionView;
109 } 121 }
110 122
  123 +#pragma mark - Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  124 +- (void)refresh {
  125 +
  126 + [self loadData];
  127 +}
  128 +
  129 +- (NSString *)timestamp {
  130 +
  131 + NSString *stamp = @"";
  132 +
  133 + stamp = [NSString stringWithFormat:@"%.3f", [[NSDate date] timeIntervalSince1970]];
  134 + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
  135 +
  136 + return stamp;
  137 +}
  138 +
  139 +- (void)autoRefresh {
  140 +
  141 + [self loadData];
  142 +}
  143 +
  144 +- (void)isNeedToRefresh {
  145 +
  146 + if (_refreshTime != 0) {
  147 + [_autoRefreshTimer invalidate];
  148 + _autoRefreshTimer = nil;
  149 + _autoRefreshTimer = [NSTimer scheduledTimerWithTimeInterval:_refreshTime target:self selector:@selector(autoRefresh) userInfo:nil repeats:YES];
  150 + }
  151 + long long timestamp = [[self timestamp] longLongValue];
  152 + if (timestamp-_timestamp > 180000) {
  153 + [self.collectionView.header beginRefreshing];
  154 + }
  155 +}
  156 +
  157 +- (void)stopAutoRefresh {
  158 +
  159 + [_autoRefreshTimer invalidate];
  160 + _autoRefreshTimer = nil;
  161 +}
  162 +
  163 +- (void)setScrollToTop:(BOOL)scrollToTop {
  164 +
  165 + _scrollToTop = scrollToTop;
  166 + self.collectionView.scrollsToTop = scrollToTop;
  167 +}
111 168
112 @end 169 @end