190 lines
10 KiB
Objective-C
190 lines
10 KiB
Objective-C
//
|
||
// GiGaQuestionVC.m
|
||
// GIGA
|
||
//
|
||
// Created by lianxiang on 2018/8/23.
|
||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||
//
|
||
|
||
#import "GiGaQuestionVC.h"
|
||
#import "GIGAQuetionView.h"
|
||
#import "GiGaQuestionModel.h"
|
||
#import "Masonry.h"
|
||
|
||
@interface GiGaQuestionVC ()
|
||
|
||
@property (nonatomic,weak) GIGAQuetionView *questionView;
|
||
@property (nonatomic,assign) NSInteger page;
|
||
@property (nonatomic,strong) NSMutableArray *questonArray;
|
||
@property (nonatomic,strong) GiGaQuestionModel *currentModel;
|
||
@property (nonatomic,strong) UILabel *questionlabel;
|
||
@property (nonatomic,strong) UIButton *nextBtn;
|
||
@end
|
||
|
||
@implementation GiGaQuestionVC
|
||
|
||
- (void)viewDidLoad {
|
||
[self addNavTitile:@"测试肤质"];
|
||
[super viewDidLoad];
|
||
// self.title = @"测试肤质";
|
||
_page = 1;
|
||
//模拟服务器数据
|
||
[self initControls];
|
||
[self setquestionArray];
|
||
[self getQuestionsInfo];
|
||
|
||
}
|
||
|
||
-(NSMutableArray *)questonArray{
|
||
if (!_questonArray) {
|
||
_questonArray = [[NSMutableArray alloc] init];
|
||
}
|
||
return _questonArray;
|
||
}
|
||
|
||
-(void)setquestionArray{
|
||
NSArray *array = @[
|
||
@{@"questionid" : @"1", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星期三", @"B:星期四", @"C:星期五"]},
|
||
@{@"questionid" : @"2", @"totalCount" : @"5", @"question" : @"这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。这里是问题,这道题的答案是AC。", @"questiontype" : @"1", @"questiontype_text" : @"多选题", @"questionselectnumber" : @"5", @"questiondescribe" : @"这里是答案解析,这里可以很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的。", @"trueanswer" : @"AC", @"userAnswer" : @[], @"tkselect" : @[@"A:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"B:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"C:这个选项是正确的。这个选项是正确的。这个选项是正确的。", @"D:这个选项是错误的。这个选项是错误的。这个选项是错误的。", @"E:这个选项是错误的。这个选项是错误的。这个选项是错误的。"]},
|
||
@{@"questionid" : @"3", @"totalCount" : @"5", @"question" : @"以下哪个牌子不是化妆品?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"化妆品,化妆品化妆品化妆品化妆品化妆品化妆品化妆品。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:化妆品", @"B:化妆品", @"C:星期五"]},
|
||
@{@"questionid" : @"4", @"totalCount" : @"5", @"question" : @"如果昨天是明天的话就好了,这样今天就周五了。真实的今天可能是星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"真实昨天是理想的明天是星期六,真实的今天是星期日?", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:星三", @"B:星", @"C:期"]},
|
||
@{@"questionid" : @"5", @"totalCount" : @"5", @"question" : @"星期几?", @"questiontype" : @"1", @"questiontype_text" : @"单选题", @"questionselectnumber" : @"3", @"questiondescribe" : @"星期三:理想今天是星期五,昨天是星期四,真实明天是理想的昨天是星期四,真实的今天是星期三。\n星期日:理想今天是星期五,明天是星期六,真实昨天是理想的明天是星期六,真实的今天是星期日。", @"trueanswer" : @"A", @"userAnswer" : @[], @"tkselect" : @[@"A:三", @"B:四", @"C:五"]},
|
||
|
||
];
|
||
for (NSDictionary *dic in array) {
|
||
GiGaQuestionModel *model = [[GiGaQuestionModel alloc] initWithDictionary:dic error:nil];
|
||
[self.questonArray addObject:model];
|
||
}
|
||
|
||
}
|
||
|
||
#pragma mark 获取当前题目信息
|
||
-(void)getQuestionsInfo{
|
||
|
||
_currentModel = _questonArray[_page - 1];
|
||
|
||
[self reloadViews];
|
||
}
|
||
|
||
#pragma mark 刷新题目
|
||
-(void)reloadViews{
|
||
//刷新问题相关数据
|
||
NSString *questionlabelText = [NSString stringWithFormat:@"%@.%@", _currentModel.questionid, _currentModel.question];
|
||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||
[paragraphStyle setLineSpacing:4.0f];
|
||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:questionlabelText];
|
||
NSDictionary *attrs =@{NSFontAttributeName:[UIFont systemFontOfSize:18]};
|
||
[attributedString setAttributes:attrs range:NSMakeRange(0, 2)];
|
||
|
||
_questionlabel.attributedText = attributedString;
|
||
|
||
[self.view layoutIfNeeded];//必加
|
||
//刷新答案相关数据
|
||
[_questionView reloadViewWithFrame:CGRectMake(0, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
|
||
|
||
|
||
}
|
||
|
||
#pragma mark 创建控件
|
||
-(void)initControls{
|
||
|
||
//顶部
|
||
UIImageView *topBackImagiew = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
|
||
topBackImagiew.backgroundColor = [UIColor lightGrayColor];
|
||
[self.view addSubview:topBackImagiew];
|
||
|
||
[topBackImagiew mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.width.mas_equalTo(KMainW - 30*2);
|
||
make.height.mas_equalTo(140);
|
||
make.top.mas_equalTo(self.view.mas_top).offset(100);
|
||
make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||
}];
|
||
UILabel *desLabel = [[UILabel alloc] init];
|
||
desLabel.text = @"通过测试可以得知您是什么肤质,有助于选择更适合的面膜";
|
||
desLabel.font = [UIFont systemFontOfSize:22];
|
||
desLabel.numberOfLines = 0;
|
||
[desLabel sizeToFit];
|
||
[topBackImagiew addSubview:desLabel];
|
||
[desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.center.mas_equalTo(topBackImagiew.center);
|
||
make.width.mas_equalTo(KMainW - 30*2 - 20*2);
|
||
|
||
}];
|
||
|
||
//问题标签
|
||
UILabel *questionLabel = [[UILabel alloc] init];
|
||
questionLabel.textColor = GIGAUIColorFromRGBA(0x292929);
|
||
questionLabel.font = [UIFont systemFontOfSize:15.f];
|
||
questionLabel.numberOfLines = 0;
|
||
[self.view addSubview:questionLabel];
|
||
self.questionlabel = questionLabel;
|
||
[self.questionlabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||
make.top.mas_equalTo(topBackImagiew.mas_bottom).offset(10);
|
||
make.right.mas_equalTo(self.view.mas_right).offset(-30);
|
||
|
||
}];
|
||
|
||
//选择题view
|
||
GIGAQuetionView *questionView = [[GIGAQuetionView alloc] init];
|
||
questionView.backgroundColor = [UIColor lightGrayColor];
|
||
[self.view addSubview:questionView];
|
||
self.questionView = questionView;
|
||
// [self.questionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
// make.top.mas_equalTo(self.questionlabel.mas_bottom).offset(10);
|
||
// make.height.mas_equalTo(0);
|
||
// make.left.mas_equalTo(self.view.mas_left).offset(30);
|
||
// make.right.mas_equalTo(self.view.mas_right).offset(-30);
|
||
// }];
|
||
|
||
//下一题
|
||
UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
nextBtn.backgroundColor = [UIColor purpleColor];
|
||
[nextBtn setTitle:@"下一个" forState:UIControlStateNormal];
|
||
[nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||
nextBtn.layer.masksToBounds = YES;
|
||
nextBtn.layer.cornerRadius = 2;
|
||
[self.view addSubview:nextBtn];
|
||
self.nextBtn = nextBtn;
|
||
|
||
|
||
[nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-100);
|
||
make.width.mas_equalTo(160);
|
||
make.height.mas_equalTo(40);
|
||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||
}];
|
||
|
||
}
|
||
|
||
-(void)nextBtnAction{
|
||
if (_page == [_currentModel.totalCount integerValue] ) {
|
||
GIGA_ShowToast(@"没有了");
|
||
return;
|
||
}
|
||
[self saveProgress];
|
||
_page ++ ;
|
||
//获取题目信息
|
||
[self getQuestionsInfo];
|
||
|
||
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES;
|
||
|
||
}
|
||
|
||
#pragma mark -做题记录
|
||
-(void)saveProgress{
|
||
NSString *answer = self.questionView.selectAnswer;
|
||
NSString *anserNum = self.questionView.qrnum;
|
||
NSString *anserid = _currentModel.questionid;
|
||
GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
// Dispose of any resources that can be recreated.
|
||
}
|
||
|
||
|
||
|
||
@end
|