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

#import "EmigratedMainViewController.h"
#import "ThroughHistoryView.h"
#import "InstructionsViewController.h"
12
#import "AnswerViewController.h"
13

曹云霄's avatar
曹云霄 committed
14
@interface EmigratedMainViewController ()<WYPopoverControllerDelegate,DismissDelegate>
15 16 17

@property (nonatomic,strong) WYPopoverController *popover;

18 19 20 21 22
/**
 闯关数据
 */
@property (nonatomic,strong) PassLevelResponse *emigratedResponse;

23 24 25 26
@end

@implementation EmigratedMainViewController

27

28 29 30 31 32 33 34 35 36 37
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self getThroughHistoryDatasAction];
}

#pragma mark - 获取闯关信息
- (void)getThroughHistoryDatasAction
{
    WS(weakSelf);
38
    PassLevelCondition *emigrated = [[PassLevelCondition alloc]init];
39
    emigrated.validEquals = YES;
40 41 42 43
    DataPage *page = [[DataPage alloc]init];
    page.page = ONE;
    page.rows = KROWS;
    emigrated.page = page;
44 45
    [XBLoadingView showHUDViewWithDefault];;
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(THROUGHLIST) WithRequestType:ZERO WithParameter:emigrated WithReturnValueBlock:^(id returnValue) {
46
        
47
        [XBLoadingView hideHUDViewWithDefault];
48 49 50
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            weakSelf.emigratedResponse = [[PassLevelResponse alloc]initWithDictionary:returnValue[@"data"] error:nil];
        }else {
51
            [XBLoadingView hideHUDViewWithDefault];
52
        }
53
        
54 55
    }WithFailureBlock:^(NSError *error) {
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
56 57 58 59 60 61 62 63 64
    }];
}

#pragma mark - 开始
- (IBAction)beginButtonClickAction:(UIButton *)sender {
    
    CGFloat width = 100;
    CGFloat height = 120;
    CGFloat interval = 30;
65 66
    for (int i=0; i<self.emigratedResponse.passLevelEntity.count; i++) {
        TOPassLevelEntity *entity = self.emigratedResponse.passLevelEntity[i];
67
        ThroughHistoryView *throughView = [ThroughHistoryView initializeView];
68
        throughView.tag = i;
69 70 71
        if ([[self class] isBlankString:entity.passResult]) {
             [throughView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectApplicableAction:)]];
        }
72 73
        throughView.titleLabel.text = entity.title;
        throughView.endDateLabel.text = [[entity.endDate componentsSeparatedByString:@" "] firstObject];
74
        throughView.frame = CGRectMake(i*width+i*interval, 0, width, height);
75
        throughView.stateImageView.image = [self emigratedState:[entity.passResult integerValue]];
76 77
        [self.throughHistoryBackScrollView addSubview:throughView];
    }
78
    self.throughHistoryBackScrollView.contentSize = CGSizeMake(self.emigratedResponse.passLevelEntity.count*width+(self.emigratedResponse.passLevelEntity.count-1)*interval, 0);
79 80 81 82 83 84 85
    WS(weakSelf);
    [UIView animateWithDuration:0.2 animations:^{
        sender.alpha = 0;
        weakSelf.throughHistoryBackScrollView.alpha = 1;
    }];
}

86 87 88 89 90
#pragma mark - 选择相应的期数
- (void)selectApplicableAction:(UITapGestureRecognizer *)sender
{
    TOPassLevelEntity *entity = self.emigratedResponse.passLevelEntity[sender.view.tag];
    AnswerViewController *answer = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"AnswerViewController"];
曹云霄's avatar
曹云霄 committed
91
    answer.delegate = self;
92 93 94 95 96
    answer.passLevelId = entity.fid;
    answer.preferredContentSize = CGSizeMake(520, 400);
    [self showPopoverView:answer];
}

曹云霄's avatar
曹云霄 committed
97 98 99 100 101 102
#pragma mark - 做题完成
- (void)dismissController
{
    [self.popover dismissPopoverAnimated:YES];
}

103 104 105 106 107 108 109 110 111
#pragma mark - 闯关说明
- (IBAction)instructionsButtonClickAction:(UIButton *)sender {
    
    InstructionsViewController *instruction = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"InstructionsViewController"];
    WS(weakSelf);
    [instruction setDismissSyntonyBlock:^{
        [weakSelf.popover dismissPopoverAnimated:YES];
    }];
    instruction.preferredContentSize = CGSizeMake(ScreenWidth/2, ScreenHeight/2);
112 113 114 115 116 117 118
    [self showPopoverView:instruction];
}

#pragma mark - 弹出框
- (void)showPopoverView:(BaseViewController *)controller
{
    self.popover = [[WYPopoverController alloc] initWithContentViewController:controller];
119 120 121
    self.popover.theme.fillBottomColor = [UIColor clearColor];
    self.popover.theme.fillTopColor = [UIColor clearColor];
    self.popover.theme.glossShadowColor = [UIColor clearColor];
122
    self.popover.delegate = self;
123 124 125
    [self.popover presentPopoverAsDialogAnimated:YES options:WYPopoverAnimationOptionFadeWithScale];
}

126 127 128 129 130
#pragma mark - 点击空白禁止收起
- (BOOL)popoverControllerShouldDismissPopover:(WYPopoverController *)popoverController
{
    return NO;
}
131 132

@end