口袋优选

KBNineNineScrollViewController.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // KBNineNineScrollViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBNineNineScrollViewController.h"
  9. #import "KBNineNineScrollChildViewController.h"
  10. #import "KBNineNineRequestViewModel.h"
  11. @interface KBNineNineScrollViewController () <SGPageTitleViewDelegate,SGPageContentViewDelegate,YHNineNineScrollChildViewControllerDelegate>{
  12. NSInteger _selectedIndex;
  13. }
  14. @property (nonatomic, strong) SGPageTitleView *pageTitleView;
  15. @property (nonatomic, strong) SGPageContentView *pageContentView;
  16. @property (nonatomic, strong) NSMutableArray *titleArr;
  17. //@property (nonatomic, strong) NSMutableArray *childArr;
  18. @end
  19. @implementation KBNineNineScrollViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self initNavBar];
  23. [self requestSublist];
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changedSexRequest) name:ChangeSex object:nil];
  25. }
  26. - (void)initNavBar {
  27. self.navigationBar.hidden = YES;
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. }
  32. - (void)initSubviews {
  33. [self.view addSubview:self.pageTitleView];
  34. [self.view addSubview:self.pageContentView];
  35. }
  36. - (void)setChildCanScroll:(BOOL)childCanScroll {
  37. for (KBNineNineScrollChildViewController *vc in self.childArr) {
  38. vc.canScroll = childCanScroll;
  39. if (!childCanScroll) {
  40. vc.collectionView.contentOffset = CGPointZero;
  41. }
  42. }
  43. }
  44. #pragma mark - request
  45. - (void)requestSublist {
  46. [KBNineNineRequestViewModel requestNineNineSublistParamType:@"1" success:^(NSArray *array) {
  47. if (array.count > 0) {
  48. for (KBNineNineScrollChannelModel *model in array) {
  49. KBNineNineScrollChildViewController *childVC = [[KBNineNineScrollChildViewController alloc] init];
  50. childVC.delegate = self;
  51. childVC.model = model;
  52. [self.titleArr addObject:model.name];
  53. [self.childArr addObject:childVC];
  54. }
  55. [self initSubviews];
  56. }
  57. } failure:^(NSError *error) {
  58. }];
  59. }
  60. - (void)changedSexRequest {
  61. [self.titleArr removeAllObjects];
  62. [self.childArr removeAllObjects];
  63. [self requestSublist];
  64. }
  65. #pragma mark - nineNineScrollChildViewControllerDelegate
  66. - (void)yh_NineNineScrollChildViewControllerDidSelectItem:(KBChildGoodModel *)model {
  67. [MobClick event:nine_classify_goods label:self.titleArr[_selectedIndex]];
  68. if ([self.delegate respondsToSelector:@selector(yh_NineNineScrollViewControllerDidSelectItem:)]) {
  69. [self.delegate yh_NineNineScrollViewControllerDidSelectItem:model];
  70. }
  71. }
  72. #pragma mark - PageTitleViewDelegate
  73. - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
  74. [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
  75. _selectedIndex = selectedIndex;
  76. [MobClick event:nine_classify label:self.titleArr[selectedIndex]];
  77. }
  78. #pragma mark - PageContentViewDelegate
  79. - (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
  80. [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
  81. _selectedIndex = targetIndex;
  82. }
  83. #pragma mark - lazy
  84. - (SGPageTitleView *)pageTitleView {
  85. if (!_pageTitleView) {
  86. SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
  87. configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
  88. configure.titleColor = [UIColor YHColorWithHex:0x222222];
  89. configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
  90. configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
  91. configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
  92. _pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, kScreenWidth, FITSIZE(40)) delegate:self titleNames:self.titleArr configure:configure];
  93. _pageTitleView.isTitleGradientEffect = NO;
  94. _pageTitleView.isOpenTitleTextZoom = YES;
  95. }
  96. return _pageTitleView;
  97. }
  98. - (SGPageContentView *)pageContentView {
  99. if (!_pageContentView) {
  100. _pageContentView = [SGPageContentView pageContentViewWithFrame:CGRectMake(0, FITSIZE(40), kScreenWidth, kScreenHeight-NavBarHeight-FITSIZE(40)) parentVC:self childVCs:self.childArr];
  101. _pageContentView.delegatePageContentView = self;
  102. }
  103. return _pageContentView;
  104. }
  105. - (NSMutableArray *)titleArr {
  106. if (!_titleArr) {
  107. _titleArr = [NSMutableArray array];
  108. }
  109. return _titleArr;
  110. }
  111. - (NSMutableArray *)childArr {
  112. if (!_childArr) {
  113. _childArr = [NSMutableArray array];
  114. }
  115. return _childArr;
  116. }
  117. @end