// // RankController.m // model // // Created by Drew on 2018/11/2. // Copyright © 2018年 Mine. All rights reserved. // #import "RankController.h" #import "RankChildController.h" #import "TabControl.h" @interface RankController () @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @property (nonatomic, strong) RankChildController* weekVC; @property (nonatomic, strong) RankChildController* monthVC; @property (weak, nonatomic) IBOutlet TabControl *tabControl; @end @implementation RankController - (void)viewDidLoad { [super viewDidLoad]; self.scrollView.delegate = self; self.tabControl.delegate = self; self.weekVC = [[RankChildController alloc] init]; self.weekVC.type = @"week"; self.monthVC = [[RankChildController alloc] init]; self.monthVC.type = @"month"; [self addChildViewController:self.weekVC]; [self addChildViewController:self.monthVC]; self.weekVC.view.frame = CGRectMake(0, 0, ScreenWidth, self.scrollView.bounds.size.height); self.monthVC.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, self.scrollView.bounds.size.height); [self.scrollView addSubview:self.weekVC.view]; [self.scrollView addSubview:self.monthVC.view]; } - (void)viewWillAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animated:NO]; } - (void)viewWillDisappear:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:YES]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.weekVC.view.frame = CGRectMake(0, 0, ScreenWidth, self.scrollView.bounds.size.height); self.monthVC.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, self.scrollView.bounds.size.height); CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = self.view.bounds; gl.startPoint = CGPointMake(0.5, 0); gl.endPoint = CGPointMake(0.5, 0.98); gl.colors = @[(__bridge id)[UIColor colorWithRed:251/255.0 green:92/255.0 blue:163/255.0 alpha:1].CGColor, (__bridge id)[UIColor colorWithRed:253/255.0 green:127/255.0 blue:141/255.0 alpha:1].CGColor]; gl.locations = @[@(0), @(1.0f)]; [self.view.layer insertSublayer:gl atIndex:0]; self.scrollView.contentSize = CGSizeMake(2 * [UIScreen mainScreen].bounds.size.width, 0); [self.weekVC.view layoutIfNeeded]; [self.monthVC.view layoutIfNeeded]; } - (IBAction)backClick:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } #pragma mark - UIScrollView Delegate - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { int index = scrollView.contentOffset.x / scrollView.frame.size.width; self.tabControl.index = index; } #pragma mark - #pragma mark - TabControl Delegate - (void)tabChange:(NSInteger)index { [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width * index, 0) animated:YES]; } #pragma mark - @end