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

#import "LuckyDrawViewController.h"
#import "LuckyDrawDetailsViewController.h"

@interface LuckyDrawViewController ()

@property (nonatomic,strong) UIViewController *currentVC;

16 17 18 19 20
/**
 指示线x约束
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionViewConstraint;

21 22 23 24 25 26 27 28 29 30 31 32 33 34
@end

@implementation LuckyDrawViewController

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

#pragma mark - 添加未抽奖和已抽奖情况
- (void)setupChildrenController
{
    /// 未抽奖
曹云霄's avatar
曹云霄 committed
35
    LuckyDrawDetailsViewController *notDrawControl = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"LuckyDrawDetailsViewController"];
36 37 38 39
    [self addChildViewController:notDrawControl];
    notDrawControl.drawValue = 1;
    self.currentVC = notDrawControl;
    /// 已抽奖
曹云霄's avatar
曹云霄 committed
40
    LuckyDrawDetailsViewController *usedDrawControl = [[[self class] getMainStoryboardClass] instantiateViewControllerWithIdentifier:@"LuckyDrawDetailsViewController"];
41 42
    usedDrawControl.drawValue = 2;
    [self addChildViewController:usedDrawControl];
43 44 45 46 47 48 49
    [self.backGroundView addSubview:notDrawControl.view];
}

#pragma mark - 布局
- (void)viewDidLayoutSubviews
{
    LuckyDrawDetailsViewController *notDrawControl = self.childViewControllers[0];
50
    notDrawControl.view.frame = CGRectMake(0, 0, self.backGroundView.mj_w, self.backGroundView.mj_h);
51 52

    LuckyDrawDetailsViewController *usedDrawControl = self.childViewControllers[1];
53 54 55
    usedDrawControl.view.frame = CGRectMake(0, 0, self.backGroundView.mj_w, self.backGroundView.mj_h);
}

56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#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.backGroundView addSubview:newViewController.view];
            self.currentVC = newViewController;
        }
    }];
}

#pragma mark - 切换ContentController
- (IBAction)paymentsButtonAndWithdrawalButtonClick:(UIButton *)sender {
    
    switch (sender.tag) {
        case 100:
        {
            self.usedDrawButton.selected = NO;
            
        }
            break;
        case 101:
        {
            self.notDrawButton.selected = NO;
        }
            break;
            
        default:
            break;
    }
    sender.selected = YES;
    [self setupInstructionsViewOrigin:sender];
    [self switchPaymentsVCAndWithdrawalVC:self.childViewControllers[sender.tag-100]];
}

#pragma mark - 设置指示线的位置
- (void)setupInstructionsViewOrigin:(UIButton *)sender
{
95
    self.instructionViewConstraint.constant = sender.x+16;
96
    [UIView animateWithDuration:0.5 delay:0.1f usingSpringWithDamping:0.5f initialSpringVelocity:0.5f options:UIViewAnimationOptionCurveEaseInOut animations:^{
97
        [self.view layoutIfNeeded];
98 99 100 101 102 103 104 105 106
    } completion:nil];
}


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

@end