123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- //
- // RQPlaceListViewController.m
- // JiaPei
- //
- // Created by 张嵘 on 2023/4/7.
- //
- #import "RQPlaceListViewController.h"
- @interface RQPlaceListViewController ()
- /// viewModel
- @property (nonatomic, readonly, strong) RQPlaceListViewModel *viewModel;
- @property (nonatomic, readwrite, strong) QMUINavigationBarScrollingAnimator *navigationAnimator;
- @property (nonatomic, readwrite, strong) RQPlaceListTableViewHeaderView *placeListTableViewHeaderView;
- @end
- @implementation RQPlaceListViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- @weakify(self)
- [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]]];
- self.tableView.backgroundColor = UIColor.clearColor;
- // [self.view addSubview:self.placeListTableViewHeaderView];
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_WIDTH * (233.f / 375.f))];
- imageView.image = RQImageNamed(@"考场搜索背景");
- [self.view addSubview:imageView];
- [self.view sendSubviewToBack:imageView];
- // [self.view bringSubviewToFront:self.placeListTableViewHeaderView];
- self.navigationAnimator = [[QMUINavigationBarScrollingAnimator alloc] init];
- self.navigationAnimator.scrollView = self.tableView;// 指定要关联的 scrollView
- self.navigationAnimator.offsetYToStartAnimation = 30;// 设置滚动的起点,值即表示在默认停靠的位置往下滚动多少距离后即触发动画,默认是 0
- self.navigationAnimator.distanceToStopAnimation = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant;// 设置从起点开始滚动多长的距离达到终点
- self.navigationAnimator.backgroundImageBlock = ^UIImage * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return [[UIImage qmui_imageWithColor:UIColor.clearColor size:CGSizeMake(RQ_SCREEN_WIDTH, RQ_APPLICATION_NAV_BAR_HEIGHT) cornerRadius:0] qmui_imageWithAlpha:progress];
- };
- self.navigationAnimator.shadowImageBlock = ^UIImage * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return [NavBarShadowImage qmui_imageWithAlpha:progress];
- };
- self.navigationAnimator.tintColorBlock = ^UIColor * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return [UIColor qmui_colorFromColor:UIColor.whiteColor toColor:UIColor.whiteColor progress:progress];
- };
- self.navigationAnimator.titleViewTintColorBlock = self.navigationAnimator.tintColorBlock;
- self.navigationAnimator.statusbarStyleBlock = ^UIStatusBarStyle(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return progress < .25 ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
- };
- // [[[RACObserve(self.viewModel, myLocationModel) deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(RQLocationModel *locationModel) {
- // @strongify(self)
- // NSString *provinceName = locationModel.myAddressModel.provinceName;
- // NSString *cityName = locationModel.myAddressModel.cityName;
- // [self.placeListTableViewHeaderView.provinceBtn setTitleNormal:RQStringIsEmpty(provinceName)? @"省份" : provinceName];
- // [self.placeListTableViewHeaderView.cityBtn setTitleNormal:RQStringIsEmpty(cityName)? @"地市" : cityName];
- // }];
- self.tableView.mj_header.automaticallyChangeAlpha = YES;
- [[RACObserve(self.viewModel, dataSource) deliverOnMainThread] subscribeNext:^(NSArray *dataSource) {
- @strongify(self)
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource.firstObject;
- NSUInteger count = groupViewModel.itemViewModels.count;
- if (!RQObjectIsNil(self.viewModel.emptyImage)) {
- if (count == 0) {
- [self showEmptyViewWithImage:self.viewModel.emptyImage text:RQStringIsEmpty(self.viewModel.emptyTex)? @"" : self.viewModel.emptyTex detailText:nil buttonTitle:nil buttonAction:nil];
- [self.view sendSubviewToBack:self.emptyView];
- } else {
- [self hideEmptyView];
- }
- }
- }];
- }
- - (void)rq_back {
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- /// 需要手动调用 navigationAnimator.statusbarStyleBlock 来告诉系统状态栏的变化
- if (self.navigationAnimator) {
- return self.navigationAnimator.statusbarStyleBlock(self.navigationAnimator, self.navigationAnimator.progress);
- }
- return [super preferredStatusBarStyle];
- }
- #pragma mark - <QMUINavigationControllerAppearanceDelegate>
- - (UIImage *)qmui_navigationBarBackgroundImage {
- return self.navigationAnimator.backgroundImageBlock(self.navigationAnimator, self.navigationAnimator.progress);
- }
- - (UIImage *)qmui_navigationBarShadowImage {
- return self.navigationAnimator.shadowImageBlock(self.navigationAnimator, self.navigationAnimator.progress);
- }
- - (UIColor *)qmui_navigationBarTintColor {
- return self.navigationAnimator.tintColorBlock(self.navigationAnimator, self.navigationAnimator.progress);
- }
- - (UIColor *)qmui_titleViewTintColor {
- return [self qmui_navigationBarTintColor];
- }
- #pragma mark - <QMUICustomNavigationBarTransitionDelegate>
- /// 为了展示接口的使用,QMUI Demo 没有打开配置表的 AutomaticCustomNavigationBarTransitionStyle,因此当 navigationBar 样式与默认样式不同时,需要手动在 customNavigationBarTransitionKey 里返回一个与其他界面不相同的值,这样才能使用自定义的 navigationBar 转场样式
- - (NSString *)customNavigationBarTransitionKey {
- return self.navigationAnimator.progress >= 1 ? nil : @"progress";
- }
- #pragma mark - OverrideMethods
- /// 配置tableView的区域
- - (UIEdgeInsets)contentInset {
- CGFloat height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f + 34.f + 8.f + 34.f + 16.f;
- height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f;
- return UIEdgeInsetsMake(height, 0, RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- RQCommonItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
- return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
- }
- - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell bindViewModel:object];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
- RQPlaceListHeaderView *headerView = [RQPlaceListHeaderView headerViewWithTableView:tableView];
- [headerView bindViewModel:groupViewModel];
- return headerView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[section];
- RQPlaceListFooterView *footerView = [RQPlaceListFooterView headerViewWithTableView:tableView];
- [footerView bindViewModel:groupViewModel];
- return footerView;
- }
- #pragma mark - LazyLoad
- - (RQPlaceListTableViewHeaderView *)placeListTableViewHeaderView {
- if (!_placeListTableViewHeaderView) {
- _placeListTableViewHeaderView = [RQPlaceListTableViewHeaderView placeListTableViewHeaderView];
- @weakify(self)
- CGFloat height = RQ_APPLICATION_NAV_BAR_HEIGHT + QMUIHelper.statusBarHeightConstant + 16.f + 34.f + 8.f + 34.f + 16.f;
- _placeListTableViewHeaderView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, height);
- [_placeListTableViewHeaderView.provinceBtn setQmui_tapBlock:^(__kindof UIControl *sender) {
- @strongify(self)
- [self showAddressPicker];
- }];
- [_placeListTableViewHeaderView.cityBtn setQmui_tapBlock:^(__kindof UIControl *sender) {
- @strongify(self)
- [self showAddressPicker];
- }];
- [[[[[RACSignal merge:@[_placeListTableViewHeaderView.searchTextField.rac_textSignal]] distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * text) {
- @strongify(self);
- [self.viewModel updateMyPlaceNameWithPlaceName:text];
- }];
- }
- return _placeListTableViewHeaderView;
- }
- - (void)showAddressPicker {
- // @weakify(self)
- // [self.placeListTableViewHeaderView.searchTextField resignFirstResponder];
- // NSString *provinceName = self.placeListTableViewHeaderView.provinceBtn.titleLabel.text;
- // NSInteger provinceIndex = [RQ_COMMON_MANAGER getProvinceIndexWithProvinceName:provinceName];
- // NSString *cityName = self.placeListTableViewHeaderView.cityBtn.titleLabel.text;
- // NSInteger cityIndex = [RQ_COMMON_MANAGER getCityIndexWithProvinceName:provinceName cityName:cityName];
- // [RQAddressPickerView showAddressPickerWithDefaultSelected:@[@(provinceIndex), @(cityIndex), @0] isAutoSelect:YES resultBlock:^(NSArray * _Nonnull selectAddressArr) {
- // @strongify(self)
- // NSString *provinceName = selectAddressArr[0];
- // NSString *cityName = selectAddressArr[1];
- // RQLocationModel *locationModel = [[RQLocationModel alloc] init];
- // RQAddressModel *addressModel = [[RQAddressModel alloc] init];
- // addressModel.provinceName = provinceName;
- // addressModel.cityName = cityName;
- // locationModel.myAddressModel = addressModel;
- // [self.viewModel updateMyLocationWithLocationModel:locationModel];
- // }];
- }
- @end
|