123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //
- // KBNineNineScrollViewController.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/17.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBNineNineScrollViewController.h"
- #import "KBNineNineScrollChildViewController.h"
- #import "KBNineNineRequestViewModel.h"
- @interface KBNineNineScrollViewController () <SGPageTitleViewDelegate,SGPageContentViewDelegate,YHNineNineScrollChildViewControllerDelegate>{
- NSInteger _selectedIndex;
- }
- @property (nonatomic, strong) SGPageTitleView *pageTitleView;
- @property (nonatomic, strong) SGPageContentView *pageContentView;
- @property (nonatomic, strong) NSMutableArray *titleArr;
- //@property (nonatomic, strong) NSMutableArray *childArr;
- @end
- @implementation KBNineNineScrollViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self initNavBar];
- [self requestSublist];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changedSexRequest) name:ChangeSex object:nil];
- }
- - (void)initNavBar {
- self.navigationBar.hidden = YES;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)initSubviews {
- [self.view addSubview:self.pageTitleView];
- [self.view addSubview:self.pageContentView];
- }
- - (void)setChildCanScroll:(BOOL)childCanScroll {
- for (KBNineNineScrollChildViewController *vc in self.childArr) {
- vc.canScroll = childCanScroll;
- if (!childCanScroll) {
- vc.collectionView.contentOffset = CGPointZero;
- }
- }
- }
- #pragma mark - request
- - (void)requestSublist {
- [KBNineNineRequestViewModel requestNineNineSublistParamType:@"1" success:^(NSArray *array) {
- if (array.count > 0) {
- for (KBNineNineScrollChannelModel *model in array) {
- KBNineNineScrollChildViewController *childVC = [[KBNineNineScrollChildViewController alloc] init];
- childVC.delegate = self;
- childVC.model = model;
- [self.titleArr addObject:model.name];
- [self.childArr addObject:childVC];
- }
- [self initSubviews];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)changedSexRequest {
- [self.titleArr removeAllObjects];
- [self.childArr removeAllObjects];
- [self requestSublist];
- }
- #pragma mark - nineNineScrollChildViewControllerDelegate
- - (void)yh_NineNineScrollChildViewControllerDidSelectItem:(KBChildGoodModel *)model {
-
- [MobClick event:nine_classify_goods label:self.titleArr[_selectedIndex]];
- if ([self.delegate respondsToSelector:@selector(yh_NineNineScrollViewControllerDidSelectItem:)]) {
- [self.delegate yh_NineNineScrollViewControllerDidSelectItem:model];
- }
- }
- #pragma mark - PageTitleViewDelegate
- - (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
- [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
- _selectedIndex = selectedIndex;
- [MobClick event:nine_classify label:self.titleArr[selectedIndex]];
- }
- #pragma mark - PageContentViewDelegate
- - (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
- [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
- _selectedIndex = targetIndex;
- }
- #pragma mark - lazy
- - (SGPageTitleView *)pageTitleView {
- if (!_pageTitleView) {
- SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
- configure.titleFont = [UIFont systemFontOfSize:FITSIZE(14)];
- configure.titleColor = [UIColor YHColorWithHex:0x222222];
- configure.titleSelectedColor = [UIColor YHColorWithHex:0xff2420];
- configure.indicatorColor = [UIColor YHColorWithHex:0xff2420];
- configure.indicatorScrollStyle = SGIndicatorScrollStyleHalf;
-
- _pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, kScreenWidth, FITSIZE(40)) delegate:self titleNames:self.titleArr configure:configure];
- _pageTitleView.isTitleGradientEffect = NO;
- _pageTitleView.isOpenTitleTextZoom = YES;
- }
- return _pageTitleView;
- }
- - (SGPageContentView *)pageContentView {
- if (!_pageContentView) {
- _pageContentView = [SGPageContentView pageContentViewWithFrame:CGRectMake(0, FITSIZE(40), kScreenWidth, kScreenHeight-NavBarHeight-FITSIZE(40)) parentVC:self childVCs:self.childArr];
- _pageContentView.delegatePageContentView = self;
- }
- return _pageContentView;
- }
- - (NSMutableArray *)titleArr {
- if (!_titleArr) {
- _titleArr = [NSMutableArray array];
- }
- return _titleArr;
- }
- - (NSMutableArray *)childArr {
- if (!_childArr) {
- _childArr = [NSMutableArray array];
- }
- return _childArr;
- }
- @end
|