RQHomePageViewController.m 24 KB

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