CommonHomeVC.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. //
  2. // CommonHomeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/4/28.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "CommonHomeVC.h"
  9. #import "CommonListCell.h"
  10. #import "MyTDGroupView.h"
  11. #import "GHRefreshCollectionView.h"
  12. #import "CommonBarCell.h"
  13. #import "CommonBarModel.h"
  14. @interface CommonHomeVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
  15. @property (weak, nonatomic) IBOutlet UIView *NavBar;
  16. @property (strong, nonatomic) UITableView *tableView;
  17. @property (strong, nonatomic) MyTDGroupView *SearchView;
  18. @property (strong, nonatomic) GHRefreshCollectionView *collectionView;
  19. @property (strong, nonatomic) NSMutableArray *collectionDataSource;
  20. @property (strong, nonatomic) NSMutableArray *dataArray;
  21. @end
  22. @implementation CommonHomeVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.fd_prefersNavigationBarHidden = YES;
  26. self.view.backgroundColor = RGB(240, 239, 244);
  27. if (@available(iOS 11.0, *)) {
  28. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  29. } else {
  30. self.automaticallyAdjustsScrollViewInsets = NO;
  31. }
  32. [self.view addSubview:self.tableView];
  33. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.right.mas_equalTo(self.view);
  35. make.top.mas_equalTo(self.NavBar.mas_bottom);
  36. if (@available(iOS 11.0, *)) {
  37. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  38. } else {
  39. make.bottom.equalTo(self.view.mas_bottom);
  40. }
  41. }];
  42. [self setBarData];
  43. [self.SearchView.button setAction:^{
  44. NSLog(@"点击搜索");
  45. }];
  46. self.tableView.delegate = self;
  47. self.tableView.dataSource = self;
  48. self.tableView.backgroundColor = [UIColor clearColor];
  49. CommonListModel * model = [[CommonListModel alloc] init];
  50. model.Title = @"钱颖一:人工智能将使中国教育仅存的优 势荡然无存";
  51. model.Name = @"钱颖一";
  52. model.Des = @"中国前沿计算机教育观察周刊";
  53. [self.dataArray addObject:model];
  54. CommonListModel * amodel = [[CommonListModel alloc] init];
  55. amodel.Title = @"大脑不擅长思考,那我们应该怎么学习?";
  56. amodel.Name = @"周明鑫";
  57. amodel.Des = @"北国教育论坛";
  58. [self.dataArray addObject:amodel];
  59. [self.tableView reloadData];
  60. }
  61. - (BOOL)hidesBottomBarWhenPushed{
  62. return NO;
  63. }
  64. #pragma mark - UITableViewDelegate
  65. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  66. return 3;
  67. }
  68. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  69. switch (section) {
  70. case 0:{
  71. return 0;
  72. }break;
  73. case 1:{
  74. return 1;
  75. }break;
  76. default:{
  77. return self.dataArray.count;
  78. }break;
  79. }
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  82. switch (indexPath.section) {
  83. case 0:{
  84. return 0.f;
  85. }break;
  86. case 1:{
  87. return 72.f;
  88. }break;
  89. default:{
  90. return UITableViewAutomaticDimension;
  91. }break;
  92. }
  93. }
  94. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  95. {
  96. switch (section) {
  97. case 0:{
  98. return 40.f;
  99. }break;
  100. case 1:{
  101. return 0.f;
  102. }break;
  103. default:{
  104. return 36.f;
  105. }break;
  106. }
  107. }
  108. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  109. {
  110. switch (section) {
  111. case 0:{
  112. return self.SearchView;
  113. }break;
  114. case 1:{
  115. UIView * view = [UIView new];
  116. return view;
  117. }break;
  118. default:{
  119. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  120. view.backgroundColor = UIColorHex(0xF5F5F5);
  121. UILabel * label = [UILabel new];
  122. label.font = [UIFont systemFontOfSize:13];
  123. label.textColor = UIColorHex(0x666666);
  124. label.text = @"最新收藏";
  125. [view addSubview:label];
  126. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.mas_offset(15);
  128. make.centerY.mas_equalTo(view);
  129. }];
  130. return view;
  131. }break;
  132. }
  133. }
  134. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  135. switch (indexPath.section) {
  136. case 1:
  137. {
  138. CommonListCell *cell = [CommonListCell configCell0:tableView indexPath:indexPath];
  139. [cell addSubview:self.collectionView];
  140. [self.collectionView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 72)];
  141. [self.collectionView reloadData];
  142. return cell;
  143. }
  144. break;
  145. default:
  146. {
  147. CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath];
  148. CommonListModel * model = [self.dataArray objectAtIndex:indexPath.row];
  149. [cell setCell1Data:model];
  150. return cell;
  151. }
  152. break;
  153. }
  154. }
  155. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  156. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  157. }
  158. #pragma mark - load
  159. - (UITableView *)tableView
  160. {
  161. if (!_tableView) {
  162. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  163. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  164. }
  165. return _tableView;
  166. }
  167. - (MyTDGroupView *)SearchView
  168. {
  169. if (!_SearchView) {
  170. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  171. }
  172. return _SearchView;
  173. }
  174. -(NSMutableArray *)dataArray{
  175. if(!_dataArray){
  176. _dataArray = [[NSMutableArray alloc] init];
  177. }
  178. return _dataArray;
  179. }
  180. -(NSMutableArray *)collectionDataSource{
  181. if(!_collectionDataSource){
  182. _collectionDataSource = [[NSMutableArray alloc] init];
  183. }
  184. return _collectionDataSource;
  185. }
  186. - (GHRefreshCollectionView *)collectionView {
  187. if (!_collectionView) {
  188. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  189. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  190. CGFloat width = SCREEN_WIDTH * 0.25;
  191. CGFloat height = 72;
  192. layout.itemSize = CGSizeMake(width, height);
  193. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  194. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  195. _collectionView.delegate = self;
  196. _collectionView.dataSource = self;
  197. _collectionView.showsHorizontalScrollIndicator = NO;
  198. [_collectionView registerNib:[UINib nibWithNibName:@"CommonBarCell" bundle:nil] forCellWithReuseIdentifier:@"CommonBarCell"];
  199. _collectionView.backgroundColor = [UIColor whiteColor];
  200. }
  201. return _collectionView;
  202. }
  203. #pragma mark UICollectionView
  204. - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{
  205. return 1;
  206. }
  207. /**********************************************************************/
  208. #pragma mark -UICollectionViewDataSource
  209. /**********************************************************************/
  210. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  211. return self.collectionDataSource.count;
  212. }
  213. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  214. {
  215. CommonBarModel *model = [self.collectionDataSource objectAtIndex:indexPath.item];
  216. CommonBarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CommonBarCell" forIndexPath:indexPath];
  217. [cell setDataWithModel:model];
  218. return cell;
  219. }
  220. /****************************************************/
  221. #pragma mark --UICollectionViewDelegateFlowLayout
  222. /****************************************************/
  223. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  224. {
  225. CGFloat width = SCREEN_WIDTH * 0.25;
  226. CGFloat height = 72;
  227. return CGSizeMake(width, height);
  228. }
  229. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  230. {
  231. return UIEdgeInsetsMake(0,0,0,0);
  232. }
  233. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  234. return 0;
  235. }
  236. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  237. return 0;
  238. }
  239. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  240. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  241. }
  242. - (void)setBarData
  243. {
  244. [self.collectionDataSource removeAllObjects];
  245. NSArray * titleArray = @[@"收藏",@"笔记",@"工具箱",@"工作台"];
  246. NSArray * imageArray = @[@"Common_collect",@"Common_note",@"Common_gjxiang",@"Common_gztai"];
  247. for (NSInteger i = 0; i < titleArray.count; i ++) {
  248. CommonBarModel * model = [[CommonBarModel alloc] init];
  249. model.name = titleArray[i];
  250. model.imageStr = imageArray[i];
  251. [self.collectionDataSource addObject:model];
  252. }
  253. }
  254. @end