VipSubjectViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // VipSubjectViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/8/28.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "VipSubjectViewController.h"
  9. #import "BtnCollectionViewCell.h"
  10. #import "VipSubjectCollectionViewCell.h"
  11. @interface VipSubjectViewController ()
  12. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  13. @end
  14. @implementation VipSubjectViewController
  15. static NSString * const reuseIdentifier = @"Cell";
  16. #pragma mark - LifeCycle
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self initUI];
  20. }
  21. - (void)viewDidAppear:(BOOL)animated {
  22. [super viewDidAppear:animated];
  23. [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.index inSection:0] atScrollPosition:(UICollectionViewScrollPositionCenteredVertically) animated:NO];
  24. }
  25. #pragma mark - Private Functions
  26. - (void)initUI {
  27. // Register cell classes
  28. [self.collectionView registerClass:[BtnCollectionViewCell class] forCellWithReuseIdentifier:@"btn"];
  29. [self.collectionView registerNib:[UINib nibWithNibName:@"VipSubjectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"VipSubjectCollectionViewCell"];
  30. [self.view addSubview:self.toolsBarView];
  31. @weakify(self)
  32. [self.toolsBarView.listBtn setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
  33. @strongify(self)
  34. [self dismissViewControllerAnimated:YES completion:^{
  35. if (self.dissmissCompletionType) {
  36. self.dissmissCompletionType(YES);
  37. }
  38. }];
  39. }];
  40. [[RACObserve(self, index) distinctUntilChanged] subscribeNext:^(id _Nullable x) {
  41. [self.collectionView reloadData];
  42. }];
  43. }
  44. - (void)initDissmissCompletionType:(DissmissCompletionType)dissmissCompletionType {
  45. self.dissmissCompletionType = dissmissCompletionType;
  46. }
  47. #pragma mark - <UICollectionViewDataSource>
  48. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  49. return 1;
  50. }
  51. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  52. return self.questionArr.count;
  53. }
  54. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  55. VipSubjectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipSubjectCollectionViewCell" forIndexPath:indexPath];
  56. [cell.subjectBtn setTitle:[NSString stringWithFormat:@"%d",(int)indexPath.row + 1] textColor:contentTextColor font:14 fotState:UIControlStateNormal];
  57. QuesTionItem *quesTionItem = self.questionArr[indexPath.row];
  58. quesTionItem.isCurrent = indexPath.row == self.index;
  59. cell.quesTionItem = quesTionItem;
  60. return cell;
  61. }
  62. #pragma mark <UICollectionViewDelegate>
  63. /*
  64. // Uncomment this method to specify if the specified item should be highlighted during tracking
  65. - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
  66. return YES;
  67. }
  68. */
  69. /*
  70. // Uncomment this method to specify if the specified item should be selected
  71. - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  72. return YES;
  73. }
  74. */
  75. /*
  76. // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
  77. - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
  78. return NO;
  79. }
  80. - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
  81. return NO;
  82. }
  83. - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
  84. }
  85. */
  86. #pragma mark - HWPanModalPresentable
  87. - (UIScrollView *)panScrollable {
  88. return self.collectionView;
  89. }
  90. - (PanModalHeight)longFormHeight {
  91. return PanModalHeightMake(PanModalHeightTypeMaxTopInset, 144);
  92. }
  93. - (CGFloat)cornerRadius {
  94. return 0.0;
  95. }
  96. - (BOOL)allowsTapBackgroundToDismiss {
  97. return NO;
  98. }
  99. - (BOOL)showDragIndicator {
  100. return NO;
  101. }
  102. #pragma mark - LazyLoad
  103. - (ToolsBarView *)toolsBarView {
  104. if (!_toolsBarView) {
  105. _toolsBarView = [[ToolsBarView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 44)];
  106. [RACObserve(self, index) subscribeNext:^(id _Nullable x) {
  107. [_toolsBarView.listBtn setTitleNormal:[NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.questionArr.count]];
  108. }];
  109. }
  110. return _toolsBarView;
  111. }
  112. @end