This commit is contained in:
lianxiang
2018-09-12 20:30:22 +08:00
parent a2de9505ee
commit 7d0027f58d
21 changed files with 805 additions and 110 deletions
@@ -9,11 +9,15 @@
#import "MaskQuestionView.h"
#import "GIGaQuestionSlider.h"
#import "GiGaAnswerViewCell.h"
#import "NYSliderPopover.h"
#import "QustionAnswer.h"
@interface MaskQuestionView()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) NSArray *dataArr;
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) GIGaQuestionSlider *slider;
@property(nonatomic,strong) NYSliderPopover *poSlider;
@end
@implementation MaskQuestionView
@@ -29,11 +33,10 @@
-(instancetype)initQuestionView:(CGRect)frame style:(MaskQuetionViewStyle)style titles:(NSArray *)titles{
self = [super initWithFrame:frame];
if (self) {
self.dataArr = titles;
self.style = style;
[self creatSubs:style titles:titles];
}
return self;
}
@@ -43,19 +46,25 @@
case MaskQuetionViewStleSliderNormal:
{
[self creatNormalStyle:titles];
[self creatNormalStyle:titles style:GIGaQuestionSliderTypeGray];
}
break;
case MaskQuetionViewStleSliderGradient:
{
[self creatNormalStyle:titles style:GIGaQuestionSliderTypeGradient];
}
break;
case MaskQuetionViewStleYesOrNO:
{
[self creatYseNoView];
}
break;
case MaskQuetionViewStyleSliderShowIndicator:
{
[self creatPopSlider];
}
break;
default:
@@ -64,10 +73,25 @@
}
}
-(void)creatNormalStyle:(NSArray *)titles{
-(void)creatPopSlider{
[self creatTab];
GIGaQuestionSlider *slider = [[GIGaQuestionSlider alloc] initWithFrame:CGRectMake(0,self.frame.size.height,self.frame.size.height, 13) type:GIGaQuestionSliderTypeGray];
NYSliderPopover *slider = [[NYSliderPopover alloc] init];
slider.frame = CGRectMake(0,self.frame.size.height,self.frame.size.height, 13);
[slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged];
self.poSlider = slider;
[self addSubview:slider];
self.poSlider.transform = CGAffineTransformMakeRotation(- M_PI/2);
}
-(void)creatNormalStyle:(NSArray *)titles style:(GIGaQuestionSliderType)type{
[self creatTab];
[self creatSliderType:type];
}
-(void)creatSliderType:(GIGaQuestionSliderType)type{
GIGaQuestionSlider *slider = [[GIGaQuestionSlider alloc] initWithFrame:CGRectMake(0,self.frame.size.height,self.frame.size.height, 13) type:type];
[slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged];
self.slider = slider;
[self addSubview:slider];
@@ -77,14 +101,88 @@
-(void)layoutSubviews{
[super layoutSubviews];
self.slider.frame = CGRectMake(90, 0, self.slider.frame.size.width, self.frame.size.height);
if (self.poSlider) {
self.poSlider.frame = CGRectMake(90, 0, self.poSlider.frame.size.width, self.frame.size.height);
}
if (self.slider) {
self.slider.frame = CGRectMake(90, 0, self.slider.frame.size.width, self.frame.size.height);
}
}
-(void)creatYseNoView{
UIButton *yesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
yesBtn.backgroundColor = GIGARGB(181, 14, 14, 1);
yesBtn.frame = CGRectMake(self.center.x - 120/2, 40, 120, 34);
[yesBtn addTarget:self action:@selector(yesBtnAction) forControlEvents:UIControlEventTouchUpInside];
NSAttributedString *preTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[yesBtn setAttributedTitle:preTitle forState:UIControlStateNormal];
yesBtn.layer.masksToBounds = YES;
yesBtn.layer.cornerRadius = 2;
[self addSubview:yesBtn];
UIButton *noBtn = [UIButton buttonWithType:UIButtonTypeCustom];
noBtn.backgroundColor = [UIColor whiteColor];
noBtn.frame = CGRectMake(self.center.x - 120/2,CGRectGetMaxY(yesBtn.frame) + 31, 120, 34);
[noBtn addTarget:self action:@selector(noBtnAction) forControlEvents:UIControlEventTouchUpInside];
NSAttributedString *noBtnTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:GIGARGB(181, 14, 14, 1)}];
[noBtn setAttributedTitle:noBtnTitle forState:UIControlStateNormal];
noBtn.layer.borderWidth = 1;
noBtn.layer.borderColor = GIGARGB(181, 14, 14, 1).CGColor;
noBtn.layer.masksToBounds = YES;
noBtn.layer.cornerRadius = 2;
[self addSubview:noBtn];
}
#pragma mark 是
-(void)yesBtnAction{
if (self.delegate && [self.delegate performSelector:@selector(yesOrNoChoiceModelAt:)]) {
[self.delegate yesOrNoChoiceModelAt:0];
}
}
#pragma mark 否
-(void)noBtnAction{
[self.delegate yesOrNoChoiceModelAt:1];
}
-(void)updateValue:(UISlider *)slider{
NSLog(@"value%f",slider.value);
GILog(@"formatvalue:%.2f",slider.value*60);
[self anlysisAnswerWithSlider:slider.value];
}
#pragma mark 题目答案解析
-(void)anlysisAnswerWithSlider:(float)value{
if (_answerList.count <=2) {
return;
}
NSInteger totalCount = _answerList.count;
//设置权值 20 ~ 50
CGFloat sliderFormatValue = value*30 + 20;
if (self.poSlider) {
[self.poSlider showPopover];
self.poSlider.popover.textLabel.text = [NSString stringWithFormat:@"%.f",sliderFormatValue];
}
//从下到上 范围50 20
//每一份高度
int powSize = 30 / (totalCount - 1);
//第几份
NSInteger index = (sliderFormatValue - 20) / powSize;
if (self.delegate && [self.delegate performSelector:@selector(sliderChangeValueShouldChoiceModelAt:)]) {
[self.delegate sliderChangeValueShouldChoiceModelAt:index];
}
}
-(void)creatTab{