| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // CustomReceiptHomeViewController.m
- // IOBSS 2.0
- //
- // Created by 刘瀚璘 on 2017.7.14
- // Copyright 2017 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 系统名称:
- // 功能描述:定制品回执页面
- #import "CustomReceiptHomeViewController.h"
- @interface CustomReceiptHomeViewController (){
- /**
- 判断是否加载过已回执界面
- */
- bool isLoad;
- }
- @end
- @implementation CustomReceiptHomeViewController
- /**
- 滑动的个数
- */
- static int _count = 2;
- #pragma mark - 公共函数
- /**
- 公共函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
- self.view.backgroundColor = [UIColor whiteColor];
- _mainScrollView.frame = CGRectMake(0, 40, Screen_Width,self.view.safeAreaLayoutGuide.layoutFrame.size.height-40);
- for (NSInteger i = 0; i < _mainScrollView.subviews.count; i++) {
- _mainScrollView.subviews[i].frame = CGRectMake(Screen_Width * i, 0, Screen_Width,CGRectGetHeight(_mainScrollView.frame));
- }
- [self.noReceiptVC viewSafeAreaInsetsDidChange];
- [self.receiptVC viewSafeAreaInsetsDidChange];
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- 滑动label位置
- @param scrollView
- */
- - (void)scrollViewDidScroll:(UIScrollView *) scrollView {
- //实时计算当前位置,实现和titleView上的按钮的联动
- CGFloat contentOffSetX = scrollView.contentOffset.x;
- CGFloat X = contentOffSetX/_count;
- CGRect frame = _sliderLabel.frame;
- frame.origin.x = X;
- _sliderLabel.frame = frame;
- }
- /**
- 滑动完成
-
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
- CGFloat contentOffSetX = scrollView.contentOffset.x;
- int index_ = contentOffSetX/Screen_Width;
- [self sliderWithTag:index_+1];
- }
- #pragma mark - 事件
- /**
- 点击已回执,未回执切换
- @param btn
- */
- - (void)sliderAction:(UIButton *) btn{
- if (self.currentIndex == btn.tag) {
- return;
- }
- if(btn.tag == 2){
- if(!isLoad){
- [_receiptVC loadDataView];
- isLoad = true;
- }
- }
- [self.view endEditing:YES];
- [self sliderAnimationWithTag:btn.tag];
- [UIView animateWithDuration:0.3 animations:^{
- _mainScrollView.contentOffset = CGPointMake(Screen_Width*(btn.tag-1), 0);
- } completion:^(BOOL finished) {
-
- }];
- }
- /**
- 滑动tag
-
- @param tag
- */
- - (void)sliderAnimationWithTag:(NSInteger) tag {
- self.currentIndex = tag;
- _receiptBtn.selected = NO;
- _noReceiptBtn.selected = NO;
-
- UIButton *sender = [self buttonWithTag:tag];
- sender.selected = YES;
- //动画
- [UIView animateWithDuration:0.3 animations:^{
- _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
-
- } completion:^(BOOL finished) {
-
- }];
- }
- /**
- 滑动tag
- @param tag
- */
- - (void)sliderWithTag:(NSInteger) tag {
- self.currentIndex = tag;
- _noReceiptBtn.selected = NO;
- _receiptBtn.selected = NO;
- if(tag == 2){
- if(!isLoad){
- [_receiptVC loadDataView];
- isLoad = true;
- }
- }
- UIButton *sender = [self buttonWithTag:tag];
- sender.selected = YES;
- //动画
- _sliderLabel.frame = CGRectMake(sender.frame.origin.x, _sliderLabel.frame.origin.y, _sliderLabel.frame.size.width, _sliderLabel.frame.size.height);
- }
- /*
- 获得导航按钮
- */
- - (UIButton *)buttonWithTag:(NSInteger ) tag {
- if (tag == 1) {
- return _noReceiptBtn;
- }
- else if (tag == 2){
- return _receiptBtn;
- }
- else{
- return nil;
- }
- }
- #pragma mark - 初始化
- /**
- 未回执实例
- @return 实例
- */
- - ( CustomNoReceiptViewController *) noReceiptVC {
- if (_noReceiptVC == nil) {
- _noReceiptVC = [[CustomNoReceiptViewController alloc] init];
- _noReceiptVC.navigation=self.navigationController;
- }
- return _noReceiptVC;
- }
- /**
- 已回执实例
- @return 实例
- */
- - (CustomReceiptViewController *) receiptVC {
- if (_receiptVC == nil) {
- _receiptVC = [[CustomReceiptViewController alloc] init];
- _receiptVC.navigation=self.navigationController; }
- return _receiptVC;
- }
- /**
- 初始化布局
- */
- - (void)initUI{
- self.navigationItem.title = @"定制品回执一览";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
-
- UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
- [self.view addSubview:navView];
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _noReceiptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_noReceiptBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_noReceiptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
-
- _noReceiptBtn.frame = CGRectMake(0, 0, Screen_Width/_count, navView.frame.size.height);
- _noReceiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_noReceiptBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [_noReceiptBtn setTitle:@"未回执" forState:UIControlStateNormal];
- _noReceiptBtn.tag = 1;
- _noReceiptBtn.selected = YES;
- [navView addSubview:_noReceiptBtn];
-
- _receiptBtn= [UIButton buttonWithType:UIButtonTypeCustom];
- _receiptBtn.frame = CGRectMake(CGRectGetMaxX(_noReceiptBtn.frame),0, Screen_Width/_count, navView.frame.size.height);
- [_receiptBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_receiptBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- _receiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_receiptBtn addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [_receiptBtn setTitle:@"已回执" forState:UIControlStateNormal];
- _receiptBtn.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- _receiptBtn.tag = 2;
- [navView addSubview: _receiptBtn];
- _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_noReceiptBtn.frame.origin.x, 40-2, Screen_Width/_count, 2)];
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/_count)-50)/2, 0, 50, 2)];
- line.backgroundColor = [UIColor redColor];
- [_sliderLabel addSubview:line];
- [navView addSubview:_sliderLabel];
- [self initSrollView];
- [self sliderWithTag:self.currentIndex+1];
- }
- /**
- 初始化srollView
- */
- - (void)initSrollView {
- _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, Screen_Width, self.view.frame.size.height)];
- _mainScrollView.delegate = self;
- _mainScrollView.backgroundColor = [UIColor whiteColor];
- _mainScrollView.pagingEnabled = YES;
- _mainScrollView.showsHorizontalScrollIndicator = NO;
- _mainScrollView.showsVerticalScrollIndicator = NO;
- [self.view addSubview:_mainScrollView];
- NSArray *views = @[self.noReceiptVC.view,self.receiptVC.view];
- for (NSInteger i = 0; i< views.count; i++) {
- //把三个vc的view依次贴到mainScrollView上面
- UIView *pageView = [[UIView alloc]initWithFrame:CGRectMake(Screen_Width * i, 0, _mainScrollView.frame.size.width, _mainScrollView.frame.size.height - 100)];
- [pageView addSubview:views[i]];
- [_mainScrollView addSubview:pageView];
- }
- _mainScrollView.contentSize = CGSizeMake(Screen_Width*(views.count), 0);
- //滚动到_currentIndex对应的tab
- [_mainScrollView setContentOffset:CGPointMake((_mainScrollView.frame.size.width)*_currentIndex, 0) animated:YES];
- }
- @end
|