RQPlaceListViewController.m 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // RQPlaceListViewController.m
  3. // JiaPei
  4. //
  5. // Created by 张嵘 on 2023/4/7.
  6. //
  7. #import "RQPlaceListViewController.h"
  8. @interface RQPlaceListViewController ()
  9. /// viewModel
  10. @property (nonatomic, readonly, strong) RQPlaceListViewModel *viewModel;
  11. @property (nonatomic, readwrite, strong) QMUINavigationBarScrollingAnimator *navigationAnimator;
  12. @property (nonatomic, readwrite, strong) RQPlaceListTableViewHeaderView *placeListTableViewHeaderView;
  13. @end
  14. @implementation RQPlaceListViewController
  15. @dynamic viewModel;
  16. #pragma mark - SystemMethod
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. @weakify(self)
  20. [self.navigationItem setLeftBarButtonItems:@[[UIBarButtonItem rq_customItemWithTitle:@"返回上一页" font:RQRegularFont_13 titleColor:UIColor.clearColor imageName:@"back_white" target:self selector:@selector(rq_back) contentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft EdgeInsetsStyle:RQButtonEdgeInsetsStyleLeft space:0]]];
  21. self.tableView.backgroundColor = UIColor.clearColor;
  22. // [self.view addSubview:self.placeListTableViewHeaderView];
  23. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_WIDTH * (233.f / 375.f))];
  24. imageView.image = RQImageNamed(@"考场搜索背景");
  25. [self.view addSubview:imageView];
  26. [self.view sendSubviewToBack:imageView];
  27. // [self.view bringSubviewToFront:self.placeListTableViewHeaderView];
  28. self.navigationAnimator = [[QMUINavigationBarScrollingAnimator alloc] init];
  29. self.navigationAnimator.scrollView = self.tableView;// 指定要关联的 scrollView
  30. self.navigationAnimator.offsetYToStartAnimation = 30;// 设置滚动的起点,值即表示在默认停靠的位置往下滚动多少距离后即触发动画,默认是 0
  31. self.navigationAnimator.distanceToStopAnimation = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant;// 设置从起点开始滚动多长的距离达到终点
  32. self.navigationAnimator.backgroundImageBlock = ^UIImage * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
  33. return [[UIImage qmui_imageWithColor:UIColor.clearColor size:CGSizeMake(RQ_SCREEN_WIDTH, RQ_APPLICATION_NAV_BAR_HEIGHT) cornerRadius:0] qmui_imageWithAlpha:progress];
  34. };
  35. self.navigationAnimator.shadowImageBlock = ^UIImage * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
  36. return [NavBarShadowImage qmui_imageWithAlpha:progress];
  37. };
  38. self.navigationAnimator.tintColorBlock = ^UIColor * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
  39. return [UIColor qmui_colorFromColor:UIColor.whiteColor toColor:UIColor.whiteColor progress:progress];
  40. };
  41. self.navigationAnimator.titleViewTintColorBlock = self.navigationAnimator.tintColorBlock;
  42. self.navigationAnimator.statusbarStyleBlock = ^UIStatusBarStyle(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
  43. return progress < .25 ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
  44. };
  45. // [[[RACObserve(self.viewModel, myLocationModel) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(RQLocationModel *locationModel) {
  46. // @strongify(self)
  47. // NSString *provinceName = locationModel.myAddressModel.provinceName;
  48. // NSString *cityName = locationModel.myAddressModel.cityName;
  49. // [self.placeListTableViewHeaderView.provinceBtn setTitleNormal:RQStringIsEmpty(provinceName)? @"省份" : provinceName];
  50. // [self.placeListTableViewHeaderView.cityBtn setTitleNormal:RQStringIsEmpty(cityName)? @"地市" : cityName];
  51. // }];
  52. self.tableView.mj_header.automaticallyChangeAlpha = YES;
  53. [[RACObserve(self.viewModel, dataSource) deliverOnMainThread] subscribeNext:^(NSArray *dataSource) {
  54. @strongify(self)
  55. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource.firstObject;
  56. NSUInteger count = groupViewModel.itemViewModels.count;
  57. if (!RQObjectIsNil(self.viewModel.emptyImage)) {
  58. if (count == 0) {
  59. [self showEmptyViewWithImage:self.viewModel.emptyImage text:RQStringIsEmpty(self.viewModel.emptyTex)? @"" : self.viewModel.emptyTex detailText:nil buttonTitle:nil buttonAction:nil];
  60. [self.view sendSubviewToBack:self.emptyView];
  61. } else {
  62. [self hideEmptyView];
  63. }
  64. }
  65. }];
  66. }
  67. - (void)rq_back {
  68. [self.navigationController popToRootViewControllerAnimated:YES];
  69. }
  70. - (UIStatusBarStyle)preferredStatusBarStyle {
  71. /// 需要手动调用 navigationAnimator.statusbarStyleBlock 来告诉系统状态栏的变化
  72. if (self.navigationAnimator) {
  73. return self.navigationAnimator.statusbarStyleBlock(self.navigationAnimator, self.navigationAnimator.progress);
  74. }
  75. return [super preferredStatusBarStyle];
  76. }
  77. #pragma mark - <QMUINavigationControllerAppearanceDelegate>
  78. - (UIImage *)qmui_navigationBarBackgroundImage {
  79. return self.navigationAnimator.backgroundImageBlock(self.navigationAnimator, self.navigationAnimator.progress);
  80. }
  81. - (UIImage *)qmui_navigationBarShadowImage {
  82. return self.navigationAnimator.shadowImageBlock(self.navigationAnimator, self.navigationAnimator.progress);
  83. }
  84. - (UIColor *)qmui_navigationBarTintColor {
  85. return self.navigationAnimator.tintColorBlock(self.navigationAnimator, self.navigationAnimator.progress);
  86. }
  87. - (UIColor *)qmui_titleViewTintColor {
  88. return [self qmui_navigationBarTintColor];
  89. }
  90. #pragma mark - <QMUICustomNavigationBarTransitionDelegate>
  91. /// 为了展示接口的使用,QMUI Demo 没有打开配置表的 AutomaticCustomNavigationBarTransitionStyle,因此当 navigationBar 样式与默认样式不同时,需要手动在 customNavigationBarTransitionKey 里返回一个与其他界面不相同的值,这样才能使用自定义的 navigationBar 转场样式
  92. - (NSString *)customNavigationBarTransitionKey {
  93. return self.navigationAnimator.progress >= 1 ? nil : @"progress";
  94. }
  95. #pragma mark - OverrideMethods
  96. /// 配置tableView的区域
  97. - (UIEdgeInsets)contentInset {
  98. CGFloat height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f + 34.f + 8.f + 34.f + 16.f;
  99. height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f;
  100. return UIEdgeInsetsMake(height, 0, RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
  101. }
  102. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  103. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  104. RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  105. return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
  106. }
  107. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  108. [cell bindViewModel:object];
  109. }
  110. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  111. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  112. RQPlaceListHeaderView *headerView = [RQPlaceListHeaderView headerViewWithTableView:tableView];
  113. [headerView bindViewModel:groupViewModel];
  114. return headerView;
  115. }
  116. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  117. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
  118. RQPlaceListFooterView *footerView = [RQPlaceListFooterView headerViewWithTableView:tableView];
  119. [footerView bindViewModel:groupViewModel];
  120. return footerView;
  121. }
  122. #pragma mark - LazyLoad
  123. - (RQPlaceListTableViewHeaderView *)placeListTableViewHeaderView {
  124. if (!_placeListTableViewHeaderView) {
  125. _placeListTableViewHeaderView = [RQPlaceListTableViewHeaderView placeListTableViewHeaderView];
  126. @weakify(self)
  127. CGFloat height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f + 34.f + 8.f + 34.f + 16.f;
  128. _placeListTableViewHeaderView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height);
  129. [_placeListTableViewHeaderView.provinceBtn setQmui_tapBlock:^(__kindof UIControl *sender) {
  130. @strongify(self)
  131. [self showAddressPicker];
  132. }];
  133. [_placeListTableViewHeaderView.cityBtn setQmui_tapBlock:^(__kindof UIControl *sender) {
  134. @strongify(self)
  135. [self showAddressPicker];
  136. }];
  137. [[[[[RACSignal merge:@[_placeListTableViewHeaderView.searchTextField.rac_textSignal]] distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * text) {
  138. @strongify(self);
  139. [self.viewModel updateMyPlaceNameWithPlaceName:text];
  140. }];
  141. }
  142. return _placeListTableViewHeaderView;
  143. }
  144. - (void)showAddressPicker {
  145. // @weakify(self)
  146. // [self.placeListTableViewHeaderView.searchTextField resignFirstResponder];
  147. // NSString *provinceName = self.placeListTableViewHeaderView.provinceBtn.titleLabel.text;
  148. // NSInteger provinceIndex = [RQ_COMMON_MANAGER getProvinceIndexWithProvinceName:provinceName];
  149. // NSString *cityName = self.placeListTableViewHeaderView.cityBtn.titleLabel.text;
  150. // NSInteger cityIndex = [RQ_COMMON_MANAGER getCityIndexWithProvinceName:provinceName cityName:cityName];
  151. // [RQAddressPickerView showAddressPickerWithDefaultSelected:@[@(provinceIndex), @(cityIndex), @0] isAutoSelect:YES resultBlock:^(NSArray * _Nonnull selectAddressArr) {
  152. // @strongify(self)
  153. // NSString *provinceName = selectAddressArr[0];
  154. // NSString *cityName = selectAddressArr[1];
  155. // RQLocationModel *locationModel = [[RQLocationModel alloc] init];
  156. // RQAddressModel *addressModel = [[RQAddressModel alloc] init];
  157. // addressModel.provinceName = provinceName;
  158. // addressModel.cityName = cityName;
  159. // locationModel.myAddressModel = addressModel;
  160. // [self.viewModel updateMyLocationWithLocationModel:locationModel];
  161. // }];
  162. }
  163. @end