add 题目

This commit is contained in:
lianxiang
2018-09-11 23:05:15 +08:00
parent 86f8824e14
commit a2de9505ee
25 changed files with 711 additions and 136 deletions
@@ -7,18 +7,24 @@
//
#import "GiGaQuestionVC.h"
#import "GIGAQuetionView.h"
#import "GiGaQuestionModel.h"
#import "Masonry.h"
#import "GiGaBaseAPiRequest.h"
#import "GiGaNetManager.h"
#import "GIGaQuestionSlider.h"
#import "MaskQuestionView.h"
#import "ExercisesModel.h"
@interface GiGaQuestionVC ()
@property (nonatomic,weak) GIGAQuetionView *questionView;
@property (nonatomic,weak) MaskQuestionView *questionView;
@property (nonatomic,assign) NSInteger page;
@property (nonatomic,strong) NSMutableArray *questonArray;
@property (nonatomic,strong) GiGaQuestionModel *currentModel;
@property (nonatomic,strong) ExercisesModel *currentModel;
@property (nonatomic,strong) UILabel *questionlabel;
@property (nonatomic,strong) UIButton *nextBtn;
@property (nonatomic,strong) UIButton *preBtn;
@end
@implementation GiGaQuestionVC
@@ -28,11 +34,81 @@
[super viewDidLoad];
// self.title = @"测试肤质";
_page = 1;
//模拟服务器数据
[self initControls];
[self setquestionArray];
[self getQuestionsInfo];
//
[self loadRequestQuestions];
//[self initUI];
}
-(void)initUI{
UIButton *numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[numberBtn setBackgroundImage:[UIImage imageNamed:@"ceshi_number"] forState:UIControlStateNormal];
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
[self.view addSubview:numberBtn];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"悄悄地告诉你小优的年龄区间是?";
titleLabel.font = [UIFont fontWithName:GIGA_FONTBOLD size:16];
titleLabel.textColor = GIGARGB(63, 63, 63, 1);
[self.view addSubview:titleLabel];
UILabel *descLabel = [[UILabel alloc] init];
descLabel.text = @"精准的选择,让小优更好的为您挑选最符合您的肤质的面膜";
descLabel.font = [UIFont fontWithName:GIGA_FONTNAME size:12];
descLabel.textColor = GIGARGB(208, 208, 208, 1);
descLabel.numberOfLines = 0;
descLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:descLabel];
[numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(31, 31));
make.top.mas_equalTo(self.view.mas_top).offset(112 + PhoneX_TopMargin);
make.left.mas_equalTo(self.view.mas_left).offset(46);
}];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(numberBtn.mas_right).offset(12);
make.centerY.mas_equalTo(numberBtn.mas_centerY);
make.right.mas_equalTo(self.view.mas_right).offset(-53);
}];
[descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(numberBtn.mas_right).offset(12);
make.top.mas_equalTo(titleLabel.mas_bottom).offset(20);
make.right.mas_equalTo(self.view.mas_right).offset(-89);
}];
//选择题view
NSArray *titles = @[@"hahah",@"呵呵呵呵",@"哦哦",@"有有u哟哦",@"呵呵呵呵"];
NSMutableArray *tit = [NSMutableArray new];
ExercisesModel *model = self.questonArray[0];
NSArray *modeA = model.answerList;
for (NSDictionary *mode in modeA){
[tit addObject:mode[@"answer"]];
}
titles = tit;
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:MaskQuetionViewStleSliderNormal titles:titles];
questionView.backgroundColor = [UIColor redColor];
[self.view addSubview:questionView];
self.questionView = questionView;
}
-(void)updateValue:(UISlider *)slider{
NSLog(@"value%f",slider.value);
GILog(@"formatvalue:%.2f",slider.value*60);
}
-(NSMutableArray *)questonArray{
@@ -42,19 +118,24 @@
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];
}
-(void)loadRequestQuestions{
NSDictionary *params = @{};
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params];
[request requstDataWithResult:^(GiGaAPIResult *result) {
if (result.success) {
NSLog(@"result:%@",result.dic);
NSArray *list = result.dic[@"list"];
NSDictionary *answer = list[0];
for (NSDictionary *answerDic in list) {
ExercisesModel *model = [[ExercisesModel alloc] initWithDictionary:answerDic error:nil];
[self.questonArray addObject:model];
}
[self initUI];
}
}];
}
@@ -62,109 +143,37 @@
-(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;
// 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(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
// //刷新答案相关数据
// [_questionView reloadViewWithFrame:CGRectMake(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 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];
// if (_page == [_currentModel.totalCount integerValue] ) {
// GIGA_ShowToast(@"没有了");
// return;
// }
// [self saveProgress];
// _page ++ ;
// //获取题目信息
// [self getQuestionsInfo];
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES;
@@ -172,10 +181,10 @@
#pragma mark -做题记录
-(void)saveProgress{
NSString *answer = self.questionView.selectAnswer;
NSString *anserNum = self.questionView.qrnum;
NSString *anserid = _currentModel.questionid;
GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
// NSString *answer = self.questionView.selectAnswer;
// NSString *anserNum = self.questionView.qrnum;
// NSString *anserid = _currentModel.questionid;
// GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
}
- (void)didReceiveMemoryWarning {