| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- //
- // RepairReceiptHomeViewController.m
- // IBOSS
- //
- // Created by guan hong hou on 2017/7/10.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:维修回执主页控制器
- #import "RepairReceiptHomeViewController.h"
- @interface RepairReceiptHomeViewController ()
- @end
- @implementation RepairReceiptHomeViewController
- static int navcount = 2; //导航数
- #pragma mark - 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- 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;
- [self initUI];
- [self setMainSrollView];
- [self sliderWithTag:self.currentIndex + 1];
- }
- /**
- 安全区视图发生变化
- */
- -(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.repairUnreceiptVC viewSafeAreaInsetsDidChange];
- [self.repairReceiptedVC viewSafeAreaInsetsDidChange];
- [super viewSafeAreaInsetsDidChange];
- }
- /**
- 维修未回执vc
-
- @return <#return value description#>
- */
- - (RepairUnreceiptVC *)repairUnreceiptVC{
- if (_repairUnreceiptVC == nil) {
- _repairUnreceiptVC = [[RepairUnreceiptVC alloc] init];
- _repairUnreceiptVC.cNav = self.navigationController;
-
- }
- return _repairUnreceiptVC;
- }
- /**
- 维修已回执vc
- @return <#return value description#>
- */
- - (RepairReceiptedVC *)repairReceiptedVC{
- if (_repairReceiptedVC == nil) {
- _repairReceiptedVC = [[RepairReceiptedVC alloc] init];
- _repairReceiptedVC.cNav = self.navigationController;
- }
- return _repairReceiptedVC;
- }
- #pragma mark - 委托函数
- /**
- 滑动label位置
-
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
- //实时计算当前位置,实现和titleView上的按钮的联动
- CGFloat contentOffSetX = scrollView.contentOffset.x;
- CGFloat X = contentOffSetX/ navcount;
- 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 - 私有函数
- /*
- 初始化UI
- */
- - (void)initUI{
- UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 40)];
- [self.view addSubview:navView];
- [self.view setBackgroundColor:[UIColor whiteColor]];
- _repairUnreceiptButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_repairUnreceiptButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_repairUnreceiptButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- _repairUnreceiptButton.frame = CGRectMake(0, 0, Screen_Width / navcount, navView.frame.size.height);
- _repairUnreceiptButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_repairUnreceiptButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [_repairUnreceiptButton setTitle:@"未回执" forState:UIControlStateNormal];
- _repairUnreceiptButton.tag = 1;
- _repairUnreceiptButton.selected = YES;
- [navView addSubview:_repairUnreceiptButton];
- _repairReceiptedButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _repairReceiptedButton.frame = CGRectMake(CGRectGetMaxX(_repairUnreceiptButton.frame),0, Screen_Width / navcount, navView.frame.size.height);
- [_repairReceiptedButton setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
- [_repairReceiptedButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
-
- _repairReceiptedButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- [_repairReceiptedButton addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventTouchUpInside];
- [_repairReceiptedButton setTitle:@"已回执" forState:UIControlStateNormal];
- _repairReceiptedButton.titleLabel.font = [UIFont systemFontOfSize:ButtonFontOfSize];
- _repairReceiptedButton.tag = 2;
- [navView addSubview: _repairReceiptedButton];
- _sliderLabel = [[UILabel alloc]initWithFrame:CGRectMake(_repairReceiptedButton.frame.origin.x, 40-2, Screen_Width / navcount, 2)];
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(((Screen_Width/navcount)-50)/2, 0, 50, 2)];
- line.backgroundColor = [UIColor redColor];
- [_sliderLabel addSubview:line];
- [navView addSubview:_sliderLabel];
- [navView addSubview:_sliderLabel];
- }
- /**
- 滑动tag
- @param tag <#tag description#>
- */
- - (void)sliderWithTag:(NSInteger)tag{
- self.currentIndex = tag;
- _repairUnreceiptButton.selected = NO;
- _repairReceiptedButton.selected = NO;
-
- 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);
-
- }
- /**
- 按钮点击事件
- @param sender <#sender description#>
- */
- - (void)sliderAction:(UIButton *)sender{
- if (self.currentIndex == sender.tag) {
- return;
- }
- [self.view endEditing:YES];
- [self sliderAnimationWithTag:sender.tag];
- [UIView animateWithDuration:0.3 animations:^{
- _mainScrollView.contentOffset = CGPointMake(Screen_Width*(sender.tag - 1), 0);
- } completion:^(BOOL finished) {
-
- }];
- }
- /**
- 滑动tag
-
- @param tag <#tag description#>
- */
- - (void)sliderAnimationWithTag:(NSInteger)tag{
- self.currentIndex = tag;
- _repairReceiptedButton.selected = NO;
- _repairUnreceiptButton.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) {
-
- }];
- }
- /*
- 获得导航按钮
- */
- - (UIButton *)buttonWithTag:(NSInteger )tag{
- if (tag == 1) {
- return _repairUnreceiptButton;
- }
- else if (tag == 2){
- return _repairReceiptedButton;
- }
-
- else{
- return nil;
- }
- }
- /**
- 初始化srollView
- */
- - (void)setMainSrollView{
- _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.repairUnreceiptVC.view,self.repairReceiptedVC.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];
- }
- /**
- 返回函数
- */
- - (void)goBack{
- [self.navigationController popViewControllerAnimated:YES];
- }
- @end
|