123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // RQExamProbabilityViewController.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/7/29.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQExamProbabilityViewController.h"
- NSString * const RQExamProbabilityUpdateNotification = @"RQExamProbabilityUpdateNotification";
- NSString * const RQExamResultListItemKey = @"RQExamResultListItemKey";
- NSString * const RQExamResultListSubjectKey = @"RQExamResultListSubjectKey";
- @interface RQExamProbabilityViewController ()
- /// viewModel
- @property (nonatomic, readonly, strong) RQExamProbabilityViewModel *viewModel;
- @property (nonatomic, readwrite, strong) QMUINavigationBarScrollingAnimator *navigationAnimator;
- @property (nonatomic, readwrite, strong) QMUIPopupMenuView *popupAtBarButtonItem;
- @property (nonatomic, readwrite, strong) UIBarButtonItem *rightBarButtonItem;
- @property (nonatomic, readwrite, strong) QMUIButton *btn;
- @property (nonatomic, readwrite, assign) BOOL isSubjectOne;
- @end
- @implementation RQExamProbabilityViewController
- @dynamic viewModel;
- #pragma mark - SystemMethod
- - (void)viewDidLoad {
- [super viewDidLoad];
- @weakify(self)
- self.isSubjectOne = (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne);
- self.navigationItem.rightBarButtonItem = self.rightBarButtonItem;
- // code here
- self.navigationAnimator = [[QMUINavigationBarScrollingAnimator alloc] init];
- self.navigationAnimator.scrollView = self.tableView;// 指定要关联的 scrollView
- self.navigationAnimator.offsetYToStartAnimation = 30;// 设置滚动的起点,值即表示在默认停靠的位置往下滚动多少距离后即触发动画,默认是 0
- self.navigationAnimator.distanceToStopAnimation = 64;// 设置从起点开始滚动多长的距离达到终点
- self.navigationAnimator.backgroundImageBlock = ^UIImage * _Nonnull(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return [[UIImage qmui_imageWithColor:RQColorFromHexString(@"#2C2D3C") 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:UIColorWhite toColor:UIColorWhite progress:progress];
- };
- self.navigationAnimator.titleViewTintColorBlock = self.navigationAnimator.tintColorBlock;
- self.navigationAnimator.statusbarStyleBlock = ^UIStatusBarStyle(QMUINavigationBarScrollingAnimator * _Nonnull animator, float progress) {
- return progress < .25 ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
- };
- }
- - (void)handleRightBarButtonItemEvent {
- if (self.popupAtBarButtonItem.isShowing) {
- [self.popupAtBarButtonItem hideWithAnimated:YES];
- } else {
- // 相对于右上角的按钮布局
- self.popupAtBarButtonItem.sourceBarItem = self.navigationItem.rightBarButtonItem;
- [self.popupAtBarButtonItem showWithAnimated:YES];
- }
- }
- #pragma mark - OverrideMethods
- /// 配置tableView的区域
- - (UIEdgeInsets)contentInset {
- return UIEdgeInsetsMake(0, 0, RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT, 0);
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
- RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
- return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
- }
- - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- [cell bindViewModel:object];
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- // 需要手动调用 navigationAnimator.statusbarStyleBlock 来告诉系统状态栏的变化
- if (self.navigationAnimator) {
- return self.navigationAnimator.statusbarStyleBlock(self.navigationAnimator, self.navigationAnimator.progress);
- }
- return [super preferredStatusBarStyle];
- }
- // 建议配合 QMUINavigationControllerAppearanceDelegate 控制不同界面切换时的 navigationBar 样式,否则需自己在 viewWillAppear:、viewWillDisappear: 里控制
- #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";
- }
- - (QMUIPopupMenuView *)popupAtBarButtonItem {
- if (!_popupAtBarButtonItem) {
- @weakify(self)
- _popupAtBarButtonItem = [[QMUIPopupMenuView alloc] init];
- _popupAtBarButtonItem.automaticallyHidesWhenUserTap = YES;// 点击空白地方消失浮层
- _popupAtBarButtonItem.maximumWidth = RQ_SCREEN_WIDTH / 2.f;
- _popupAtBarButtonItem.shouldShowItemSeparator = YES;
- _popupAtBarButtonItem.tintColor = RQ_MAIN_BACKGROUNDCOLOR;
- _popupAtBarButtonItem.items = @[[QMUIPopupMenuButtonItem itemWithImage:nil title:@"科目一" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
- @strongify(self)
- [self.btn setTitleNormal:aItem.title];
- [RQNotificationCenter postNotificationName:RQExamProbabilityUpdateNotification object:@{
- RQExamResultListItemKey : RQ_COMMON_MANAGER.examResultOneListArr,
- RQExamResultListSubjectKey : @(RQHomePageSubjectType_SubjectOne),
- }];
- [aItem.menuView hideWithAnimated:YES];
- }],
- [QMUIPopupMenuButtonItem itemWithImage:nil title:@"科目四" handler:^(QMUIPopupMenuButtonItem * _Nonnull aItem) {
- @strongify(self)
- [self.btn setTitleNormal:aItem.title];
- [RQNotificationCenter postNotificationName:RQExamProbabilityUpdateNotification object:@{
- RQExamResultListItemKey : RQ_COMMON_MANAGER.examResultFourListArr,
- RQExamResultListSubjectKey : @(RQHomePageSubjectType_SubjectFour),
- }];
- [aItem.menuView hideWithAnimated:YES];
- }],
- ];
- }
- return _popupAtBarButtonItem;
- }
- - (QMUIButton *)btn {
- if (!_btn) {
- _btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
- [_btn setTitle:self.isSubjectOne? @"科目一" : @"科目四" forState:UIControlStateNormal];
- [_btn setImage:RQImageNamed(@"向下") withTitle:self.isSubjectOne? @"科目一" : @"科目四" textColor:RQ_MAIN_BACKGROUNDCOLOR Font:16 fotState:UIControlStateNormal];
- [_btn addTarget:self action:@selector(handleRightBarButtonItemEvent) forControlEvents:UIControlEventTouchUpInside];
- _btn.imagePosition = QMUIButtonImagePositionRight;
- _btn.spacingBetweenImageAndTitle = 8.f;
- }
- return _btn;
- }
- - (UIBarButtonItem *)rightBarButtonItem {
- if (!_rightBarButtonItem) {
- _rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.btn];
- }
- return _rightBarButtonItem;
- }
- @end
|