RQHomePageViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. //
  2. // RQHomePageViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/21.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQHomePageViewController.h"
  9. #import "MapManager.h"
  10. #import "RQQRCodeViewController.h"
  11. #import "ScanVC.h"
  12. #import "ScanPageVC.h"
  13. #import "DistenceTooLongMapVC.h"
  14. @interface RQHomePageViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, SDCycleScrollViewDelegate>
  15. /// viewModel
  16. @property (nonatomic, readonly, strong) RQHomePageViewModel *viewModel;
  17. @property (nonatomic, readwrite, strong) RQHomePageTitleView *homePageTitleView;
  18. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  19. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  20. @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
  21. //投诉建议入口-可共用
  22. @property (nonatomic, readwrite, strong) NYFloatingSuggestViewModel *floatingSuggestViewModel;
  23. @property (nonatomic, readwrite, strong) NYFloatingSuggestView *floatingSuggestView;
  24. //集中式理论
  25. @property (nonatomic, readwrite, assign) BOOL isNeedTest;
  26. @property (nonatomic, readwrite, assign) BOOL isCloseAudio;
  27. @property (nonatomic, readwrite, assign) NSInteger maxTime;
  28. @property (nonatomic, readwrite, copy) NSString *scanType;
  29. @property (nonatomic, readwrite, copy) NSString *scanData;
  30. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation;
  31. @end
  32. @implementation RQHomePageViewController
  33. @dynamic viewModel;
  34. #pragma mark - SystemMethod
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. /// 初始化
  38. [self rq_setup];
  39. // if (myDelegate.isLogin) {
  40. // //更新登录信息 如果是登录状态的时候
  41. // reLogin(self);
  42. // }
  43. }
  44. - (void)viewDidAppear:(BOOL)animated {
  45. [super viewDidAppear:animated];
  46. if (RQ_COMMON_MANAGER.JSJP_APP_ICON_NEED_CHANGE) {
  47. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_NewRule" completionHandler:^(NSError * _Nullable error) {
  48. if (error != nil) {
  49. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  50. }
  51. }];
  52. } else {
  53. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_Old" completionHandler:^(NSError * _Nullable error) {
  54. if (error != nil) {
  55. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  56. }
  57. }];
  58. }
  59. }
  60. - (void)viewDidLayoutSubviews {
  61. [super viewDidLayoutSubviews];
  62. self.pagerView.frame = CGRectMake(0, (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  63. }
  64. - (void)dealloc{
  65. //移除指定的通知,不然会造成内存泄露
  66. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil];
  67. }
  68. #pragma mark - PrivateMethods
  69. /// 初始化
  70. - (void)rq_setup {
  71. /// set up ...
  72. @weakify(self)
  73. [self.view addSubview:self.pagerView];
  74. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  75. @strongify(self)
  76. //头像
  77. CGFloat sBoader = (kNavBarHeight - 35)/2.0;
  78. UIButton *sideBtn = [[UIButton alloc] initWithFrame:CGRectMake(sBoader, kStatusHeight + sBoader, kNavBarHeight - sBoader*2, kNavBarHeight - sBoader*2)];
  79. [self.view addSubview:sideBtn];
  80. UIImageView *iv = [[UIImageView alloc] initWithFrame:sideBtn.bounds];
  81. [iv sd_setImageWithURL:[NSURL URLWithString:userModel.photo] placeholderImage:[UIImage imageNamed:@"头像"]];
  82. iv.contentMode = UIViewContentModeScaleAspectFill;
  83. [iv setBoardWid:1 Color:RQ_MAIN_COLOR CornerRadius:6];
  84. [iv setRound];
  85. [sideBtn addSubview:iv];
  86. [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside];
  87. UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn];
  88. self.navigationItem.leftBarButtonItem = bbi0;
  89. }];
  90. if (myDelegate.isSyn) {
  91. myDelegate.isSyn = NO;
  92. if ([myDelegate.markQuestionTableData isKindOfClass:[NSMutableArray class]]) {
  93. if (myDelegate.markQuestionTableData.count == 0) {
  94. [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题
  95. if (myDelegate.isLogin)//更新版本 先做一次同步
  96. {
  97. [self syncQuestion];
  98. }
  99. }
  100. }
  101. }
  102. //监听题库变化
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil];
  104. // 注册手势驱动
  105. // __weak typeof(self)weakSelf = self;
  106. // [self cw_registerShowIntractiveWithEdgeGesture:YES transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
  107. // if (direction == CWDrawerTransitionFromLeft) { // 左侧滑出
  108. // [weakSelf defaultAnimationFromLeft];
  109. // }
  110. // }];
  111. self.navigationItem.titleView = self.homePageTitleView;
  112. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  113. //二维码扫描登录网页
  114. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"erWeiMa.png"] originImageScaleToSize:CGSizeMake(22.5, 22.5)] style:UIBarButtonItemStyleDone target:self action:@selector(clickToScan)];
  115. item.tintColor = RQ_MAIN_COLOR;
  116. if (RQ_USER_MANAGER.currentUser.city && ![RQ_USER_MANAGER.currentUser.city isEqualToString:@""] && [RQ_USER_MANAGER.currentUser.city isEqualToString:@""]) {
  117. }
  118. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  119. @strongify(self)
  120. if ([RQ_USER_MANAGER.currentUser.isOpenScan boolValue]) {
  121. [self.navigationItem setRightBarButtonItem:item];
  122. } else {
  123. self.navigationItem.rightBarButtonItems = @[];
  124. }
  125. }];
  126. [[[[RQNotificationCenter rac_addObserverForName:RQCarTypeChangeNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * _Nullable x) {
  127. @strongify(self)
  128. self.pagerView.defaultSelectedIndex = 0;
  129. self.categoryView.defaultSelectedIndex = 0;
  130. [self.pagerView reloadData];
  131. [self.categoryView reloadData];
  132. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  133. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  134. }];
  135. [[[[RACObserve(RQ_COMMON_MANAGER, APP_SWITCH) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) {
  136. @strongify(self)
  137. // self.pagerView.defaultSelectedIndex = 0;
  138. // self.categoryView.defaultSelectedIndex = 0;
  139. [self.pagerView reloadData];
  140. [self.categoryView reloadData];
  141. }];
  142. //投诉建议
  143. [self addFloatingSuggestView];
  144. // [[RACSignal combineLatest:@[RACObserve(RQ_VIP_Module, isVip), RACObserve(RQ_COMMON_MANAGER, APP_SWITCH)] reduce:^id (NSNumber *isVip, NSNumber *APP_SWITCH) {
  145. // if (RQ_VIP_Module.isVip && RQ_COMMON_MANAGER.APP_SWITCH) {
  146. // return @(NO);
  147. // } else {
  148. // return @(RQ_COMMON_MANAGER.APP_SWITCH);
  149. // }
  150. // }] subscribeNext:^(NSNumber *APP_SWITCH) {
  151. // if (APP_SWITCH.boolValue != RQ_COMMON_MANAGER.APP_SWITCH) {
  152. // RQ_COMMON_MANAGER.APP_SWITCH = NO;
  153. // }
  154. // }];
  155. }
  156. //添加到主窗口
  157. - (void)addFloatingSuggestView {
  158. [self.view addSubview:self.floatingSuggestView];
  159. [self.floatingSuggestView mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.right.mas_equalTo(self.view).offset(-20.f);
  161. make.bottom.mas_equalTo(self.view).offset(-60.f);
  162. make.width.mas_equalTo(116.f);
  163. make.height.mas_equalTo(89.f);
  164. }];
  165. [self.floatingSuggestView bindViewModel:self.floatingSuggestViewModel];//绑定RAC
  166. }
  167. - (void)notificationAction:(NSNotification *)notification{
  168. self.pagerView.defaultSelectedIndex = 0;
  169. self.categoryView.defaultSelectedIndex = 0;
  170. [self.pagerView reloadData];
  171. [self.categoryView reloadData];
  172. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  173. if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) {
  174. return;
  175. }
  176. }
  177. /**显示左边抽屉
  178. */
  179. - (void)showLeftViewAction {
  180. [self defaultAnimationFromLeft];
  181. }
  182. - (void)clickToScan {
  183. @weakify(self)
  184. if (RQ_USER_MANAGER.isShouldLogin) {
  185. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  186. @strongify(self)
  187. if (isSuccess) {
  188. if (activationModel.isShare) {
  189. if (activationModel.isActive == 1) {
  190. [self gotoPt];
  191. } else {
  192. [RQ_VIP_Module gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city];
  193. }
  194. } else {
  195. [self gotoPt];
  196. }
  197. }
  198. }];
  199. }
  200. }
  201. - (void)gotoPt {
  202. @weakify(self)
  203. [QMUITips showLoadingInView:DefaultTipsParentView];
  204. RQQRCodeViewController *vc = [[RQQRCodeViewController alloc] init];
  205. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  206. [vc initBlock:^(NSString * _Nonnull result, BOOL isSuccess) {
  207. if (isSuccess) {
  208. [RQ_PT_Object_Module uploadScanCodeVerifyWithQRCodeResultStr:result resultBlock:^(BOOL isSuccess) {
  209. }];
  210. } else {
  211. ShowMsg(result);
  212. }
  213. }];
  214. [LOCATION_MANAGER updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  215. @strongify(self)
  216. if (success) {
  217. if (RQ_USER_MANAGER.verifyLevel == 0) {
  218. [self presentViewController:vc animated:YES completion:^{
  219. [QMUITips hideAllTips];
  220. }];
  221. } else {
  222. if (bmkLocation.mockProbability <= RQ_USER_MANAGER.verifyLevel) {
  223. [self presentViewController:vc animated:YES completion:^{
  224. [QMUITips hideAllTips];
  225. }];
  226. } else {
  227. [RQ_SHARE_FUNCTION showAlertWithMessage:@"请勿篡改定位信息!" completion:^(NSUInteger selectedOtherButtonIndex) {
  228. [QMUITips hideAllTips];
  229. }];
  230. }
  231. }
  232. } else {
  233. [RQ_SHARE_FUNCTION showAlertWithMessage:@"定位失败!" completion:^(NSUInteger selectedOtherButtonIndex) {
  234. [QMUITips hideAllTips];
  235. }];
  236. }
  237. }];
  238. }
  239. - (void)getMyLocation {
  240. //定位功能
  241. [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."];
  242. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  243. [MBProgressHUD rq_hideHUD];
  244. if (success) {
  245. _myLocation = location.coordinate;
  246. [self studentQrcode];
  247. }
  248. }];
  249. }
  250. /** 扫描二维码调取接口 */
  251. - (void)studentQrcode {
  252. if (![Util connectedToNetWork]) {
  253. showMsgUnconnect();
  254. return;
  255. }
  256. if (_myLocation.longitude == 0.0) {
  257. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置获取失败,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  258. return;
  259. }
  260. NSMutableArray *arr=[NSMutableArray array];
  261. [arr addPro:@"studentOutid" Value:RQ_USER_MANAGER.currentUser.outId];
  262. [arr addPro:@"qrcode" Value:_scanData];
  263. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  264. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",_myLocation.longitude]];
  265. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",_myLocation.latitude]];
  266. [arr addPro:@"type" Value:_scanType];
  267. [arr addPro:@"telType" Value:@"ios"];
  268. NSString *method = @"studentQrcode";
  269. NSString *str = [_scanType isEqualToString: @"1"] ? @"签到中...":@"签退中...";
  270. [MBProgressHUD rq_showProgressHUD:str];
  271. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  272. [MBProgressHUD rq_hideHUD];
  273. if (!root) {
  274. ShowMsg(@"操作失败,请重试!");
  275. [Tools playAudioWithString:@"操作失败,请重试!"];
  276. return;
  277. }
  278. if ([root[@"code"] integerValue] == 0) {//代表操作成功
  279. if ([_scanType isEqualToString:@"1"] || [_scanType isEqualToString:@"3"]) {
  280. myDelegate.trainStateLabel.text = @"理论学习中...";
  281. }
  282. if ([_scanType isEqualToString:@"2"]) {
  283. myDelegate.trainStateLabel.text = @"";
  284. }
  285. if (_isNeedTest) {
  286. switch ([_scanType integerValue]) { //1、签到 2、签退 3、过程验证
  287. case 1://签到成功
  288. if (_maxTime > 0) {
  289. [self setNotificationWithFireTime:_maxTime];
  290. }
  291. break;
  292. case 2://签退
  293. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  294. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  295. }
  296. break;
  297. case 3://验证成功
  298. if (_maxTime > 0) {
  299. [self setNotificationWithFireTime:_maxTime];
  300. }
  301. break;
  302. default:
  303. break;
  304. }
  305. }
  306. }
  307. if ([root[@"code"] integerValue] == 2) {//距离理论教室位置较远
  308. NSString *str = root[@"msg"];
  309. if (str.length < 1) {
  310. return;
  311. }
  312. NSArray *mapArray = [str componentsSeparatedByString:@";"];
  313. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[mapArray lastObject] preferredStyle:UIAlertControllerStyleAlert];
  314. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  315. [alert addAction:[UIAlertAction actionWithTitle:@"查看位置详情" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  316. //进入地图页面 传入两个点 一个距离 lng lat len
  317. if (mapArray.count > 3) {
  318. // lng = 123.467129,
  319. // lat = 41.813997
  320. //122.769684;41.515881;66822;您当前距离理论教室位置66822米,请到理论教室扫码!
  321. DistenceTooLongMapVC *mapVC = [[DistenceTooLongMapVC alloc] init];
  322. mapVC.lat1 = _myLocation.latitude;
  323. mapVC.lng1 = _myLocation.longitude;
  324. mapVC.lat2 = [mapArray[1] floatValue];
  325. mapVC.lng2 = [mapArray[0] floatValue];
  326. mapVC.distence = mapArray[2];
  327. mapVC.skipMspBlock = ^{
  328. _myLocation.longitude = 0.0;
  329. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置已重置,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  330. };
  331. [self navPushHideTabbarToVC:mapVC];
  332. }
  333. }]];
  334. [self presentViewController:alert animated:true completion:nil];
  335. return;
  336. }
  337. [Tools playAudioWithString:root[@"msg"]];
  338. ShowMsg(root[@"msg"]);
  339. }];
  340. }
  341. //语音播报或者推送
  342. - (void)setNotificationWithFireTime:(NSInteger)fireTime {
  343. //移除旧的通知
  344. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  345. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  346. }
  347. //定义本地通知对象
  348. UILocalNotification *notification = [[UILocalNotification alloc]init];
  349. //设置调用时间
  350. notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime];
  351. //设置通知属性
  352. notification.alertBody = @"极速驾培提醒您"; //通知主体
  353. notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数
  354. notification.alertAction = @"打开应用"; //待机界面的滑动动作提示
  355. notification.soundName = @"TrainTest.mp3";//收到通知时播放的声音,默认消息声音
  356. // 通知参数
  357. NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"ShiCaoPeriodVC_reTakePhoto", nil];
  358. notification.userInfo = userDict;
  359. //调用通知
  360. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  361. }
  362. //更新第一次进入同步数据
  363. - (void)syncQuestion {
  364. if (![Util connectedToNetWork]) {
  365. return;
  366. }
  367. [self getMyQuestionType:@"" Subject:@""];
  368. }
  369. - (void)getMyQuestionType:(NSString*)type Subject:(NSString*)subject {
  370. NSMutableArray *arr = [NSMutableArray array];
  371. [arr addPro:@"user" Value:RQ_USER_MANAGER.currentUser._id];
  372. [arr addPro:@"type" Value:type];
  373. [arr addPro:@"subject" Value:subject];
  374. [arr addPro:@"carType" Value:RQ_YDTQuestion_Module.car_type];
  375. [arr addPro:@"isPage" Value:@"0"];
  376. [arr addPro:@"pageSize" Value:@"0"];
  377. [arr addPro:@"currentPage" Value:@"0"];
  378. NSString* method = @"getMyQuestionFavs";
  379. [MBProgressHUD rq_showProgressHUD:@"收藏、错题同步中,请稍后..."];
  380. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  381. //NSLog(@"同步错题收藏---->%@--->%@",arr,root);
  382. if (!root || [root[@"code"] integerValue] == 1) {
  383. [MBProgressHUD rq_hideHUD];
  384. ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步");
  385. return;
  386. }
  387. NSArray *body = [root objectForKey:@"body"];
  388. if (body.count > 0) {
  389. if ([DB_Que_Helper deleteAllMarkQuestion]) {
  390. [DB_Que_Helper setMarkQuestionWithArray:body];
  391. }
  392. }
  393. [MBProgressHUD rq_hideHUD];
  394. [MBProgressHUD rq_showTips:@"题库错题、收藏、排除已同步完毕"];
  395. }];
  396. }
  397. // 仿QQ从左侧划出
  398. - (void)defaultAnimationFromLeft {
  399. if (RQ_USER_MANAGER.isShouldLogin) {
  400. [RQ_APPDELEGATE.services pushViewModel:[[RQSettingViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil] animated:YES];
  401. }
  402. }
  403. #pragma mark - JXPagerViewDelegate
  404. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  405. return [UIView new];
  406. }
  407. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  408. return 0.f;
  409. }
  410. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  411. return [RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"]? 0.f : 49.f;
  412. }
  413. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  414. return self.categoryView;
  415. }
  416. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  417. //和categoryView的item数量一致
  418. return self.categoryView.titles.count;
  419. }
  420. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  421. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  422. NSInteger myIndex = index;
  423. RQ_YDTQuestion_Module.subject = myIndex;
  424. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  425. RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(RQHomePageCarType_Car), RQHomePageSubjectTypeKey : @(myIndex)}];
  426. RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel];
  427. return homePageSubjectFourViewController;
  428. }
  429. #pragma mark - JXCategoryViewDelegate
  430. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  431. RQ_YDTQuestion_Module.subject = index;
  432. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  433. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  434. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  435. }
  436. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  437. }
  438. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  439. }
  440. - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
  441. // if (RQ_YDTQuestion_Module.subject == leftIndex) {
  442. // /// 向左滑 向右滚动
  443. // if (1.f - ratio > 0.7) {
  444. // RQ_YDTQuestion_Module.subject = rightIndex;
  445. // }
  446. // } else if (RQ_YDTQuestion_Module.subject == rightIndex) {
  447. // /// 向右滑 向左滚动
  448. // if (1.f - ratio > 0.3) {
  449. // RQ_YDTQuestion_Module.subject = leftIndex;
  450. // }
  451. // }
  452. }
  453. #pragma mark - JXPagerMainTableViewGestureDelegate
  454. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  455. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  456. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  457. return NO;
  458. }
  459. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  460. }
  461. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  462. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  463. if (list.contentScrollView == scrollView) {
  464. return YES;
  465. }
  466. }
  467. return NO;
  468. }
  469. #pragma mark - SDCycleScrollViewDelegate
  470. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  471. }
  472. #pragma mark - LazyLoad
  473. - (JXPagerView *)pagerView {
  474. if (!_pagerView) {
  475. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  476. _pagerView.mainTableView.gestureDelegate = self;
  477. _pagerView.defaultSelectedIndex = 0;
  478. _pagerView.mainTableView.bounces = NO;
  479. _pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  480. }
  481. return _pagerView;
  482. }
  483. - (JXCategoryTitleView *)categoryView {
  484. if (!_categoryView) {
  485. _categoryView = [[JXCategoryTitleView alloc] init];
  486. _categoryView.titles = self.titles;
  487. _categoryView.backgroundColor = [UIColor whiteColor];
  488. _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1;
  489. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  490. _categoryView.titleFont = RQRegularFont(17);
  491. _categoryView.titleSelectedFont = RQSemiboldFont(22);
  492. _categoryView.titleColorGradientEnabled = YES;
  493. _categoryView.titleLabelZoomEnabled = YES;
  494. _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
  495. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  496. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  497. lineView.indicatorColor = RQ_MAIN_COLOR;
  498. lineView.indicatorHeight = 4;
  499. lineView.verticalMargin = 0;
  500. _categoryView.indicators = @[lineView];
  501. _categoryView.defaultSelectedIndex = 0;
  502. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  503. _categoryView.delegate = self;
  504. }
  505. return _categoryView;
  506. }
  507. - (NSArray<NSString *> *)titles {
  508. return @[@"科一", @"科二", @"科三", @"科四"];
  509. }
  510. - (RQHomePageTitleView *)homePageTitleView {
  511. if (!_homePageTitleView) {
  512. _homePageTitleView = [RQHomePageTitleView homePageTitleViewView];
  513. _homePageTitleView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH / 3.f, RQ_APPLICATION_NAV_BAR_HEIGHT);
  514. }
  515. return _homePageTitleView;
  516. }
  517. - (NYFloatingSuggestViewModel *)floatingSuggestViewModel {
  518. if(!_floatingSuggestViewModel){
  519. _floatingSuggestViewModel = [[NYFloatingSuggestViewModel alloc] init];
  520. }
  521. return _floatingSuggestViewModel;
  522. }
  523. - (NYFloatingSuggestView *)floatingSuggestView {
  524. if (!_floatingSuggestView) {
  525. _floatingSuggestView = [NYFloatingSuggestView floatingSuggestView];
  526. }
  527. return _floatingSuggestView;
  528. }
  529. @end