新UI马甲包

FSBaseViewController.m 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. //
  2. // FSBaseViewController.m
  3. // FSScrollViewNestTableViewDemo
  4. //
  5. // Created by huim on 2017/5/23.
  6. // Copyright © 2017年 fengshun. All rights reserved.
  7. //
  8. #import "FSBaseViewController.h"
  9. #import "FSBaseTableView.h"
  10. #import "FSBaseTopTableViewCell.h"
  11. #import "FSScrollContentView.h"
  12. #import "FSScrollContentViewController.h"
  13. #import "FSBottomTableViewCell.h"
  14. #import "HCHomeChannelModel.h"
  15. #import "ActivityIndicatorView.h"
  16. #import "LDMorePicCollectionModel.h"
  17. #import "LDSearchCoupleWebViewController.h"
  18. #import "LDSuperListModel.h"
  19. #import <AlibabaAuthSDK/ALBBSession.h>
  20. #import "AccountTool.h"
  21. #import <AlibabaAuthSDK/ALBBSDK.h>
  22. #import "HCLoginViewController.h"
  23. @interface FSBaseViewController ()<UITableViewDelegate,UITableViewDataSource,FSPageContentViewDelegate,FSSegmentTitleViewDelegate,YHMorePicCollectionCellDelegate>
  24. {
  25. UILabel *titleLabel;
  26. NSMutableArray *contentVCs;
  27. FSBaseTopTableViewCell *cell;
  28. //默认选中的model
  29. HCHomeChannelModel *selectModel;
  30. NSInteger selectIndex;//选中的下标
  31. }
  32. @property (nonatomic, strong) FSBaseTableView *tableView;
  33. @property (nonatomic, strong) FSBottomTableViewCell *contentCell;
  34. @property (nonatomic, strong) FSSegmentTitleView *titleView;
  35. @property (nonatomic, assign) BOOL canScroll;
  36. @property (nonatomic, strong) NSArray *morePicCollectionArr;
  37. @property (nonatomic, strong) NSMutableArray *modelArr;
  38. @property (nonatomic, strong) NSMutableArray *titleArr;
  39. @property (nonatomic, strong) NSMutableArray *vcArray;
  40. @end
  41. @implementation FSBaseViewController
  42. - (void)dealloc
  43. {
  44. [[NSNotificationCenter defaultCenter] removeObserver:self];
  45. }
  46. #pragma mark-----viewDidLoad
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.view.backgroundColor =[UIColor whiteColor];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus) name:@"leaveTop" object:nil];
  51. [self loadChildViewController];
  52. [self setupSubViews];
  53. [self.view addSubview:self.tableView];
  54. [self loadHotRecomPicCollectionData];
  55. }
  56. /**
  57. 加载菜单栏目
  58. */
  59. - (void)loadHotRecomPicCollectionData {
  60. [HCHttp get:GoldCollectiongroups params:nil success:^(id json) {
  61. self.morePicCollectionArr = [NSArray yy_modelArrayWithClass:[LDMorePicCollectionModel class] json:json[@"data"]];
  62. [cell setModelDatas:self.morePicCollectionArr];
  63. [self.tableView reloadData];
  64. } failure:^(NSError *error) {
  65. }];
  66. }
  67. - (void)setupSubViews
  68. {
  69. self.navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
  70. contentVCs =[NSMutableArray array];
  71. self.view.backgroundColor = [UIColor YHColorWithHex:0xFFF3DE];
  72. self.automaticallyAdjustsScrollViewInsets = NO;
  73. self.canScroll = YES;
  74. self.tableView.backgroundColor = [UIColor YHColorWithHex:0xFFF3DE];
  75. //下移20像素的时候执行
  76. if([ self.tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)])
  77. {
  78. if(@available(iOS 11.0, *)) {
  79. self.tableView.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
  80. }else{// Fallback on earlier versions
  81. }}
  82. }
  83. #pragma mark notify
  84. - (void)changeScrollStatus//改变主视图的状态
  85. {
  86. self.canScroll = YES;
  87. self.contentCell.cellCanScroll = NO;
  88. }
  89. #pragma mark UITableView
  90. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  91. {
  92. if (self.titleArr.count == 0) {
  93. return 1;
  94. }
  95. return 2;
  96. }
  97. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  98. {
  99. return 1;
  100. }
  101. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. if (indexPath.section == 0) {
  104. //圆形菜单高度
  105. CGFloat bannerHeight =KStatusBarHeight+Fitsize(115);
  106. if (indexPath.row == 0) {
  107. if (self.morePicCollectionArr==nil||self.morePicCollectionArr.count==0) {
  108. return .1+bannerHeight;
  109. }
  110. NSInteger offHeight=0;
  111. if (iPhone5) {
  112. offHeight=10;
  113. }
  114. NSInteger Crow=1;
  115. NSInteger Coff=-1;
  116. NSInteger CrowItemSum=5;
  117. Coff=self.morePicCollectionArr.count%CrowItemSum;
  118. if (Coff!=0) {
  119. CrowItemSum=4;
  120. Coff=self.morePicCollectionArr.count%CrowItemSum;
  121. if (Coff!=0) {
  122. CrowItemSum=3;
  123. Coff=self.morePicCollectionArr.count%CrowItemSum;
  124. if (Coff!=0) {
  125. CrowItemSum=5;
  126. Crow++;
  127. }
  128. }
  129. }
  130. Crow=self.morePicCollectionArr.count/CrowItemSum;
  131. if (Coff!=0) {
  132. Crow++;
  133. }
  134. NSInteger totalHeight = (SCREEN_WIDTH/4+offHeight)*Crow;
  135. return totalHeight+bannerHeight;
  136. }
  137. }
  138. return CGRectGetHeight(self.view.bounds);
  139. }
  140. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  141. {
  142. if (section == 0) {
  143. return 0;
  144. }
  145. return FITSIZE(22);
  146. }
  147. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  148. {
  149. return 0.1;
  150. }
  151. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  152. {
  153. if (self.titleArr.count == 0) {
  154. return nil;
  155. }
  156. self.titleView = [[FSSegmentTitleView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), FITSIZE(22)) titles:self.titleArr delegate:self indicatorType:FSIndicatorTypeEqualTitle];
  157. self.titleView.selectIndex=selectIndex;
  158. self.titleView.titleSelectColor =[UIColor YHColorWithHex:0xEBB189];
  159. self.titleView.backgroundColor = [UIColor clearColor];
  160. return self.titleView;
  161. }
  162. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. static NSString *FSBaseTopTableViewCellIdentifier = @"FSBaseTopTableViewCellIdentifier";
  165. if (indexPath.section == 1) {
  166. _contentCell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  167. if (!_contentCell) {
  168. _contentCell = [[FSBottomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  169. for (NSString *title in self.titleArr) {
  170. FSScrollContentViewController *vc = [[FSScrollContentViewController alloc]init];
  171. vc.title = title;
  172. vc.str = title;
  173. [contentVCs addObject:vc];
  174. }
  175. _contentCell.viewControllers = contentVCs;
  176. _contentCell.pageContentView = [[FSPageContentView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavBarHeight) childVCs:contentVCs parentVC:self delegate:self];
  177. [_contentCell.contentView addSubview:_contentCell.pageContentView];
  178. }
  179. _contentCell.selectionStyle=UITableViewCellSelectionStyleNone;
  180. if (contentVCs.count != 0) {
  181. FSScrollContentViewController *vc =contentVCs[selectIndex];
  182. vc.model = self.modelArr[selectIndex];
  183. _tableView.scrollEnabled = YES;
  184. self.contentCell.pageContentView.contentViewCurrentIndex = selectIndex;
  185. }
  186. return _contentCell;
  187. }
  188. if (indexPath.row == 0) {
  189. cell = [tableView dequeueReusableCellWithIdentifier:FSBaseTopTableViewCellIdentifier];
  190. if (!cell) {
  191. cell = [[FSBaseTopTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FSBaseTopTableViewCellIdentifier];
  192. }
  193. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  194. cell.backgroundColor =[UIColor YHColorWithHex:0xFFF3DE];
  195. cell.delegate=self;
  196. [cell setModelDatas:self.morePicCollectionArr];
  197. return cell;
  198. }
  199. return nil;
  200. }
  201. #pragma mark--
  202. -(void)selectIndex:(NSInteger )endIndex
  203. {
  204. FSScrollContentViewController *vc =contentVCs[endIndex];
  205. selectIndex=endIndex;
  206. HCHomeChannelModel *models=self.modelArr[endIndex];
  207. selectModel = models;
  208. vc.model = models;
  209. }
  210. -(void)YHMorePicCollectionCellDidSelectedItem:(NSInteger)index
  211. {
  212. LDSuperListModel *model= self.morePicCollectionArr[index];
  213. //点击大牌商品
  214. LDSearchCoupleWebViewController *searchCoupleWeb = [[LDSearchCoupleWebViewController alloc] init];
  215. searchCoupleWeb.url = model.url;
  216. searchCoupleWeb.jsString = model.ios_js_string;
  217. searchCoupleWeb.name = model.name;
  218. if ([[ALBBSession sharedInstance] isLogin] && [AccountTool isLogin]) {
  219. //进入
  220. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  221. }else if (![AccountTool isLogin]) {
  222. //未登录
  223. HCLoginViewController *login = [[HCLoginViewController alloc] init];
  224. [self presentViewController:login animated:YES completion:nil];
  225. }else if (![[ALBBSession sharedInstance] isLogin]) {
  226. //淘宝未授权
  227. ALBBSDK *albbSDK = [ALBBSDK sharedInstance];
  228. [albbSDK setAppkey:ALBC_APP_KEY];
  229. [albbSDK setAuthOption:NormalAuth];
  230. [albbSDK auth:self successCallback:^(ALBBSession *session){
  231. [[NSNotificationCenter defaultCenter] postNotificationName:ChangeTaoBaoAuthor object:nil];
  232. [self.navigationController pushViewController:searchCoupleWeb animated:YES];
  233. } failureCallback:^(ALBBSession *session,NSError *error){
  234. NSLog(@"session == %@,error == %@",session,error);
  235. }];
  236. }
  237. }
  238. #pragma mark FSSegmentTitleViewDelegate
  239. - (void)FSContenViewDidEndDecelerating:(FSPageContentView *)contentView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
  240. {
  241. self.titleView.selectIndex = endIndex;
  242. _tableView.scrollEnabled = YES;//此处其实是监测scrollview滚动,pageView滚动结束主tableview可以滑动,或者通过手势监听或者kvo,这里只是提供一种实现方式
  243. [self selectIndex:endIndex];
  244. }
  245. - (void)FSSegmentTitleView:(FSSegmentTitleView *)titleView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
  246. {
  247. self.contentCell.pageContentView.contentViewCurrentIndex = endIndex;
  248. [self selectIndex:endIndex];
  249. }
  250. - (void)FSContentViewDidScroll:(FSPageContentView *)contentView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex progress:(CGFloat)progress
  251. {
  252. _tableView.scrollEnabled = NO;//pageView开始滚动主tableview禁止滑动
  253. }
  254. #pragma mark UIScrollView
  255. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  256. {
  257. if (self.titleArr.count != 0) {
  258. CGFloat bottomCellOffset = [self.tableView rectForSection:1].origin.y - NavBarHeight;
  259. if (scrollView.contentOffset.y >= bottomCellOffset) {
  260. scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
  261. if (self.canScroll) {
  262. self.canScroll = NO;
  263. self.contentCell.cellCanScroll = YES;
  264. }
  265. titleLabel.hidden=NO;
  266. cell.imgv.hidden=YES;
  267. cell.collectionView.hidden=YES;
  268. }else{
  269. if (!self.canScroll) {//子视图没到顶部
  270. scrollView.contentOffset = CGPointMake(0, bottomCellOffset);
  271. }
  272. titleLabel.hidden=YES;
  273. cell.imgv.hidden=NO;
  274. cell.collectionView.hidden=NO;
  275. }
  276. }
  277. }
  278. #pragma mark LazyLoad
  279. - (FSBaseTableView *)tableView
  280. {
  281. if (!_tableView) {
  282. _tableView = [[FSBaseTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  283. _tableView.delegate = self;
  284. _tableView.dataSource = self;
  285. _tableView.backgroundColor =[UIColor whiteColor];
  286. _tableView.showsVerticalScrollIndicator=NO;
  287. _tableView.showsHorizontalScrollIndicator=NO;
  288. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  289. _tableView.mj_header =[MJRefreshNormalHeader headerWithRefreshingBlock:^{
  290. [self loadChildViewController];
  291. }];
  292. titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(FITSIZE(60), 20, SCREEN_WIDTH-FITSIZE(120), NavBarHeight-20)];
  293. titleLabel.text=@"超级大牌";
  294. [self.view addSubview:titleLabel];
  295. titleLabel.textColor=[UIColor YHColorWithHex:0xD98C0D];
  296. titleLabel.textAlignment=NSTextAlignmentCenter;
  297. titleLabel.font =[UIFont systemFontOfSize:FITSIZE(16)];
  298. titleLabel.hidden=YES;
  299. }
  300. return _tableView;
  301. }
  302. -(void)backAction
  303. {
  304. [self.navigationController popViewControllerAnimated:YES];
  305. }
  306. #pragma mark---分类
  307. - (void)loadChildViewController {
  308. [HCCacheHttp get:ChannelList params:nil success:^(id json, BOOL isCache) {
  309. [self.modelArr removeAllObjects];
  310. [self.titleArr removeAllObjects];
  311. NSArray *list = json[@"data"];
  312. for (int i = 0; i < list.count; i++) {
  313. NSDictionary *dic = list[i];
  314. HCHomeChannelModel *model = [HCHomeChannelModel yy_modelWithJSON:dic];
  315. if (i == 0) {
  316. selectIndex = 0;
  317. selectModel = model;
  318. }
  319. if (_model.Id.integerValue == model.Id.integerValue) {
  320. selectIndex = i;
  321. selectModel = model;
  322. }
  323. [self.modelArr addObject:model];
  324. [self.titleArr addObject:model.name];
  325. }
  326. [self.tableView.mj_header endRefreshing];
  327. [self.tableView reloadData];
  328. } failure:^(NSError *error) {
  329. }];
  330. }
  331. #pragma mark-分类下的列表
  332. -(void)channellist
  333. {
  334. NSString *url =[NSString stringWithFormat:@"%@/api/v2/channel/SuperBrand",BaseURL];
  335. NSDictionary *dics=@{@"position":@"3",@"category_id":selectModel.Id};
  336. [HCHttp post:url params:dics success:^(id json) {
  337. } failure:^(NSError *error) {
  338. }];
  339. }
  340. - (NSMutableArray *)modelArr {
  341. if (!_modelArr) {
  342. _modelArr = [NSMutableArray array];
  343. }
  344. return _modelArr;
  345. }
  346. - (NSMutableArray *)titleArr {
  347. if (!_titleArr) {
  348. _titleArr = [NSMutableArray array];
  349. }
  350. return _titleArr;
  351. }
  352. - (NSMutableArray *)vcArray {
  353. if (!_vcArray) {
  354. _vcArray = [NSMutableArray array];
  355. }
  356. return _vcArray;
  357. }
  358. @end