123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // VipSubjectViewController.m
- // jiaPei
- //
- // Created by 张嵘 on 2019/8/28.
- // Copyright © 2019 JCZ. All rights reserved.
- //
- #import "VipSubjectViewController.h"
- #import "BtnCollectionViewCell.h"
- #import "VipSubjectCollectionViewCell.h"
- @interface VipSubjectViewController ()
- @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
- @end
- @implementation VipSubjectViewController
- static NSString * const reuseIdentifier = @"Cell";
- #pragma mark - LifeCycle
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.index inSection:0] atScrollPosition:(UICollectionViewScrollPositionCenteredVertically) animated:NO];
- }
- #pragma mark - Private Functions
- - (void)initUI {
- // Register cell classes
- [self.collectionView registerClass:[BtnCollectionViewCell class] forCellWithReuseIdentifier:@"btn"];
- [self.collectionView registerNib:[UINib nibWithNibName:@"VipSubjectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"VipSubjectCollectionViewCell"];
- [self.view addSubview:self.toolsBarView];
- @weakify(self)
- [self.toolsBarView.listBtn setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
- @strongify(self)
- [self dismissViewControllerAnimated:YES completion:^{
- if (self.dissmissCompletionType) {
- self.dissmissCompletionType(YES);
- }
- }];
- }];
-
- [[RACObserve(self, index) distinctUntilChanged] subscribeNext:^(id _Nullable x) {
- [self.collectionView reloadData];
- }];
- }
- - (void)initDissmissCompletionType:(DissmissCompletionType)dissmissCompletionType {
- self.dissmissCompletionType = dissmissCompletionType;
- }
- #pragma mark - <UICollectionViewDataSource>
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.questionArr.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- VipSubjectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VipSubjectCollectionViewCell" forIndexPath:indexPath];
- [cell.subjectBtn setTitle:[NSString stringWithFormat:@"%d",(int)indexPath.row + 1] textColor:contentTextColor font:14 fotState:UIControlStateNormal];
- QuesTionItem *quesTionItem = self.questionArr[indexPath.row];
- quesTionItem.isCurrent = indexPath.row == self.index;
- cell.quesTionItem = quesTionItem;
- return cell;
- }
- #pragma mark <UICollectionViewDelegate>
- /*
- // Uncomment this method to specify if the specified item should be highlighted during tracking
- - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- */
- /*
- // Uncomment this method to specify if the specified item should be selected
- - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- */
- /*
- // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
- return NO;
- }
-
- - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
- return NO;
- }
-
- - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
-
- }
- */
- #pragma mark - HWPanModalPresentable
- - (UIScrollView *)panScrollable {
- return self.collectionView;
- }
- - (PanModalHeight)longFormHeight {
- return PanModalHeightMake(PanModalHeightTypeMaxTopInset, 144);
- }
- - (CGFloat)cornerRadius {
- return 0.0;
- }
- - (BOOL)allowsTapBackgroundToDismiss {
- return NO;
- }
- - (BOOL)showDragIndicator {
- return NO;
- }
- #pragma mark - LazyLoad
- - (ToolsBarView *)toolsBarView {
- if (!_toolsBarView) {
- _toolsBarView = [[ToolsBarView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 44)];
- [RACObserve(self, index) subscribeNext:^(id _Nullable x) {
- [_toolsBarView.listBtn setTitleNormal:[NSString stringWithFormat:@"%ld/%lu",[x integerValue] + 1,(unsigned long)self.questionArr.count]];
- }];
- }
- return _toolsBarView;
- }
- @end
|