CardDetailsViewController.m 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//
//  CardDetailsViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/10/19.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CardDetailsViewController.h"
#import "CardDontUseViewController.h"
#import "CardBeenUseViewController.h"

@interface CardDetailsViewController ()

/**
 *  当前的控制器
 */
@property (nonatomic,strong) UIViewController *currentVC;

20 21 22 23 24
/**
 指示线约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionViewConstraint;

25 26 27 28 29 30 31 32 33 34 35 36 37
@end

@implementation CardDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChildViewController];
}

#pragma mark - 添加卡劵详情vc
- (void)addChildViewController
{
曹云霄's avatar
曹云霄 committed
38
    /// 未领取
曹云霄's avatar
曹云霄 committed
39
    CardDontUseViewController *dontUseVc = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardDontUseViewController"];
40
    [self addChildViewController:dontUseVc];
曹云霄's avatar
曹云霄 committed
41
    /// 已领取
曹云霄's avatar
曹云霄 committed
42
    CardBeenUseViewController *beenUseVc = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardBeenUseViewController"];
43
    // 审批中
44
    CardBeenUseViewController *examineUseVc = [[[self class] getMainStoryboardClass]instantiateViewControllerWithIdentifier:@"CardBeenUseViewController"];
45 46
    examineUseVc.cardState = CHECK;
    [self addChildViewController:examineUseVc];
47

曹云霄's avatar
曹云霄 committed
48
    beenUseVc.cardState = ACTIVED;
49
    [self addChildViewController:beenUseVc];
曹云霄's avatar
曹云霄 committed
50
    /// 已使用
曹云霄's avatar
曹云霄 committed
51
    CardBeenUseViewController *usedVc = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"CardBeenUseViewController"];
52
    usedVc.cardState = USED;
曹云霄's avatar
曹云霄 committed
53
    [self addChildViewController:usedVc];
54 55 56 57 58 59 60 61
    [self.cardBackgroundView addSubview:dontUseVc.view];
    self.currentVC = dontUseVc;
}

#pragma mark - 布局
- (void)viewDidLayoutSubviews
{
    CardDontUseViewController *dontUseVc = self.childViewControllers[0];
62
    dontUseVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
63 64

    CardBeenUseViewController *beenUseVc = self.childViewControllers[1];
65
    beenUseVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
66 67

    CardBeenUseViewController *examineUseVc = self.childViewControllers[2];
68
    examineUseVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
69 70

    CardBeenUseViewController *usedVc = self.childViewControllers[3];
曹云霄's avatar
曹云霄 committed
71
    usedVc.view.frame = CGRectMake(0, 0, self.cardBackgroundView.mj_w, self.cardBackgroundView.mj_h);
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
}


#pragma mark - 切换已使用卡劵、未使用卡劵
- (void)switchPaymentsVCAndWithdrawalVC:(UIViewController *)newViewController
{
    [self transitionFromViewController:self.currentVC toViewController:newViewController duration:0.5 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
        if (finished) {
            [self.cardBackgroundView addSubview:newViewController.view];
            self.currentVC = newViewController;
        }
    }];
}

#pragma mark - 切换ContentController
- (IBAction)paymentsButtonAndWithdrawalButtonClick:(UIButton *)sender {
    
89 90 91 92
    for (id object in self.view.subviews) {
        if ([object isKindOfClass:[UIButton class]]) {
            UIButton *button = (UIButton *)object;
            button.selected = NO;
曹云霄's avatar
曹云霄 committed
93
        }
94
    }
曹云霄's avatar
曹云霄 committed
95
    sender.selected = YES;
96 97 98 99 100 101 102
    [self setupInstructionsViewOrigin:sender];
    [self switchPaymentsVCAndWithdrawalVC:self.childViewControllers[sender.tag-100]];
}

#pragma mark - 设置指示线的位置
- (void)setupInstructionsViewOrigin:(UIButton *)sender
{
103
    self.instructionViewConstraint.constant = sender.x+16;
104
    [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
105
        [self.view layoutIfNeeded];
106 107 108 109 110 111 112 113 114
    } completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end