| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // NewMycollectionViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/8/13.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "NewMycollectionViewController.h"
- #import "SectionChooseView.h"
- #import "CollectionCGViewController.h"
- #import "CollectionXQViewController.h"
- #import "CollectionXMViewController.h"
- @interface NewMycollectionViewController ()<UIScrollViewDelegate,SectionChooseVCDelegate>{
- NSString *gender;//模拟性别区分
- }
- //底部滚动ScrollView
- @property (nonatomic, strong) UIScrollView *contentScrollView;
- @property(nonatomic,strong)SectionChooseView *sectionChooseView;
- @end
- @implementation NewMycollectionViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"我的收藏"];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showFirstVC) name:@"ABC" object:nil];
-
- // Do any additional setup after loading the view.
- //添加所有子控制器
- [self setupChildViewController];
-
- //初始化UIScrollView
- [self setupUIScrollView];
- // Do any additional setup after loading the view.
- }
- - (void)showFirstVC {
-
- [self showVc:0];
- }
- #pragma mark -添加所有子控制器
- -(void)setupChildViewController {
-
- CollectionCGViewController *VC1 = [[CollectionCGViewController alloc] init];
-
- [self addChildViewController:VC1];
-
-
- CollectionXQViewController *VC2 = [[CollectionXQViewController alloc] init];
-
- [self addChildViewController:VC2];
-
- CollectionXMViewController *VC3 = [[CollectionXMViewController alloc] init];
-
- [self addChildViewController:VC3];
-
- }
- - (void)setupUIScrollView {
-
- NSArray *arr1 = @[@"成果", @"需求",@"项目"];
- // 创建底部滚动视图
- self.contentScrollView = [[UIScrollView alloc] init];
- _contentScrollView.frame = CGRectMake(0, NavHeader-1, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader);
- _contentScrollView.contentSize = CGSizeMake(self.view.frame.size.width * arr1.count, 0);
- _contentScrollView.backgroundColor = [UIColor clearColor];
- // 开启分页
- _contentScrollView.pagingEnabled = YES;
- // 没有弹簧效果
- _contentScrollView.bounces = NO;
- // 隐藏水平滚动条
- _contentScrollView.showsHorizontalScrollIndicator = NO;
- // 设置代理
- _contentScrollView.delegate = self;
- [self.view addSubview:_contentScrollView];
-
-
- self.sectionChooseView = [[SectionChooseView alloc] initWithFrame:CGRectMake(0, NavHeader-1, self.view.frame.size.width, NavHeader) titleArray:arr1];
- self.sectionChooseView.selectIndex = 0;
- self.sectionChooseView.delegate = self;
- self.sectionChooseView.normalBackgroundColor = NewClearColor;
- self.sectionChooseView.selectBackgroundColor = [UIColor whiteColor];;
- self.sectionChooseView.titleNormalColor = [UIColor whiteColor];
- self.sectionChooseView.titleSelectColor = [UIColor colorWithString:@"#0097F4"];
- self.sectionChooseView.normalTitleFont = 16;
- self.sectionChooseView.selectTitleFont = 16;
- self.sectionChooseView.backgroundColor = NewClearColor;
- [self.view addSubview:self.sectionChooseView];
- }
- #pragma mark -SMCustomSegmentDelegate
- - (void)SectionSelectIndex:(NSInteger)selectIndex {
-
- NSLog(@"---------%ld",(long)selectIndex);
-
- // 1 计算滚动的位置
- CGFloat offsetX = selectIndex * self.view.frame.size.width;
- self.contentScrollView.contentOffset = CGPointMake(offsetX, 0);
-
- // 2.给对应位置添加对应子控制器
- [self showVc:selectIndex];
- }
- #pragma mark -显示控制器的view
- /**
- * 显示控制器的view
- *
- * @param index 选择第几个
- *
- */
- - (void)showVc:(NSInteger)index {
-
- CGFloat offsetX = index * self.view.frame.size.width;
-
- UIViewController *vc = self.childViewControllers[index];
-
- // 判断控制器的view有没有加载过,如果已经加载过,就不需要加载
- if (vc.isViewLoaded) return;
-
- [self.contentScrollView addSubview:vc.view];
- vc.view.frame = CGRectMake(offsetX, 0, self.view.frame.size.width, self.view.frame.size.height);
- }
- #pragma mark -UIScrollViewDelegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
-
-
- // 计算滚动到哪一页
- NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
-
- // 1.添加子控制器view
- [self showVc:index];
-
- // 2.把对应的标题选中
- self.sectionChooseView.selectIndex = index;
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|