add test
This commit is contained in:
parent
a2de9505ee
commit
7d0027f58d
|
|
@ -106,6 +106,9 @@
|
|||
83A22718212ABDFF00B3E75C /* GiGaBlockButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22717212ABDFF00B3E75C /* GiGaBlockButton.m */; };
|
||||
83A2271F212AC8C100B3E75C /* GiGaUserLoginVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A2271D212AC8C100B3E75C /* GiGaUserLoginVC.m */; };
|
||||
83A22720212AC8C100B3E75C /* GiGaUserLoginVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83A2271E212AC8C100B3E75C /* GiGaUserLoginVC.xib */; };
|
||||
83BC8A862148BE8A00820437 /* NYSliderPopover.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BC8A822148BE8A00820437 /* NYSliderPopover.m */; };
|
||||
83BC8A872148BE8A00820437 /* NYPopover.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BC8A842148BE8A00820437 /* NYPopover.m */; };
|
||||
83BC8A8A2148D28300820437 /* QustionAnswer.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BC8A892148D28300820437 /* QustionAnswer.m */; };
|
||||
83BDC0582147B89900E74E0D /* GiGaAnswerViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BDC0562147B89900E74E0D /* GiGaAnswerViewCell.m */; };
|
||||
83BDC0592147B89900E74E0D /* GiGaAnswerViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83BDC0572147B89900E74E0D /* GiGaAnswerViewCell.xib */; };
|
||||
83BFAE67213CCF10004EF801 /* GiGaMineUserViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BFAE65213CCF10004EF801 /* GiGaMineUserViewCell.m */; };
|
||||
|
|
@ -317,6 +320,12 @@
|
|||
83A2271C212AC8C100B3E75C /* GiGaUserLoginVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiGaUserLoginVC.h; sourceTree = "<group>"; };
|
||||
83A2271D212AC8C100B3E75C /* GiGaUserLoginVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiGaUserLoginVC.m; sourceTree = "<group>"; };
|
||||
83A2271E212AC8C100B3E75C /* GiGaUserLoginVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GiGaUserLoginVC.xib; sourceTree = "<group>"; };
|
||||
83BC8A822148BE8A00820437 /* NYSliderPopover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYSliderPopover.m; sourceTree = "<group>"; };
|
||||
83BC8A832148BE8A00820437 /* NYPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYPopover.h; sourceTree = "<group>"; };
|
||||
83BC8A842148BE8A00820437 /* NYPopover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYPopover.m; sourceTree = "<group>"; };
|
||||
83BC8A852148BE8A00820437 /* NYSliderPopover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYSliderPopover.h; sourceTree = "<group>"; };
|
||||
83BC8A882148D28300820437 /* QustionAnswer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QustionAnswer.h; sourceTree = "<group>"; };
|
||||
83BC8A892148D28300820437 /* QustionAnswer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QustionAnswer.m; sourceTree = "<group>"; };
|
||||
83BDC0552147B89900E74E0D /* GiGaAnswerViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiGaAnswerViewCell.h; sourceTree = "<group>"; };
|
||||
83BDC0562147B89900E74E0D /* GiGaAnswerViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiGaAnswerViewCell.m; sourceTree = "<group>"; };
|
||||
83BDC0572147B89900E74E0D /* GiGaAnswerViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GiGaAnswerViewCell.xib; sourceTree = "<group>"; };
|
||||
|
|
@ -865,6 +874,8 @@
|
|||
83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */,
|
||||
83773FBA214769230014EE4C /* ExercisesModel.h */,
|
||||
83773FBB214769230014EE4C /* ExercisesModel.m */,
|
||||
83BC8A882148D28300820437 /* QustionAnswer.h */,
|
||||
83BC8A892148D28300820437 /* QustionAnswer.m */,
|
||||
);
|
||||
path = Model;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -872,6 +883,7 @@
|
|||
83835BC0212E66A1001480F2 /* View */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
83BC8A812148BE8A00820437 /* NYSliderPopover */,
|
||||
83835BC8212E8045001480F2 /* GIGAQuetionView.h */,
|
||||
83835BC9212E8045001480F2 /* GIGAQuetionView.m */,
|
||||
83773FBD214791E10014EE4C /* GIGaQuestionSlider.h */,
|
||||
|
|
@ -985,6 +997,17 @@
|
|||
path = Controller;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
83BC8A812148BE8A00820437 /* NYSliderPopover */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
83BC8A822148BE8A00820437 /* NYSliderPopover.m */,
|
||||
83BC8A832148BE8A00820437 /* NYPopover.h */,
|
||||
83BC8A842148BE8A00820437 /* NYPopover.m */,
|
||||
83BC8A852148BE8A00820437 /* NYSliderPopover.h */,
|
||||
);
|
||||
path = NYSliderPopover;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
83E40B2C21218B7E008149C4 /* LogIn */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -1263,12 +1286,15 @@
|
|||
83BFAE7B213D3F3A004EF801 /* MaskTimeCircularProgressView.m in Sources */,
|
||||
8314D2112133ABE500B458BF /* WeiIXinApiManager.m in Sources */,
|
||||
83BDC0582147B89900E74E0D /* GiGaAnswerViewCell.m in Sources */,
|
||||
83BC8A862148BE8A00820437 /* NYSliderPopover.m in Sources */,
|
||||
83773FC52147A5CC0014EE4C /* MaskQuestionView.m in Sources */,
|
||||
83835BCA212E8045001480F2 /* GIGAQuetionView.m in Sources */,
|
||||
8361B3CE212155C200238FEB /* ViewController.m in Sources */,
|
||||
8361B4382121847600238FEB /* UINavigationBar+Custom.m in Sources */,
|
||||
83BFAE6C213CD0E3004EF801 /* GiGaMineInfoViewCell.m in Sources */,
|
||||
83BC8A872148BE8A00820437 /* NYPopover.m in Sources */,
|
||||
83346AD4212BFF6E0054D597 /* UserGuardViewController.m in Sources */,
|
||||
83BC8A8A2148D28300820437 /* QustionAnswer.m in Sources */,
|
||||
8357ADC92123BFCA000816F2 /* GiGaUserManager.m in Sources */,
|
||||
83835BB3212E50ED001480F2 /* ActiveMesagelistVC.m in Sources */,
|
||||
83835BC3212E677C001480F2 /* GiGaQuestionVC.m in Sources */,
|
||||
|
|
|
|||
|
|
@ -2,22 +2,4 @@
|
|||
<Bucket
|
||||
type = "0"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "GIGA/Modules/Mask/Exercises/Controller/GiGaQuestionVC.m"
|
||||
timestampString = "558370995.03293"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "102"
|
||||
endingLineNumber = "102"
|
||||
landmarkName = "-initUI"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
//[self.navigationController.navigationBar cnSetBackgroundColor:GIGARGB(216, 216, 216, 1)];
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ typedef void (^responseBlock)(NSDictionary *responseDict, NSDictionary *response
|
|||
+(void)request:(NSString *)url params:(NSDictionary *)param
|
||||
success:(void (^)(id response))success
|
||||
failure:(void (^)(NSError *err))failure;
|
||||
+(void)userLoginrequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error))completionHandler;
|
||||
|
||||
// 测试题 , 登录
|
||||
+(void)userbodyRequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error))completionHandler;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -98,13 +98,14 @@
|
|||
}
|
||||
|
||||
//登录body传参数
|
||||
+(void)userLoginrequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response,NSDictionary *resDic, NSError * _Nullable error))completionHandler
|
||||
+(void)userbodyRequest:(NSString *)url params:(NSDictionary *)param completionHandler:(nullable void (^)(NSURLResponse *response,NSDictionary *resDic, NSError * _Nullable error))completionHandler
|
||||
{
|
||||
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||
NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]];
|
||||
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration];
|
||||
NSMutableURLRequest *requst = [[AFJSONRequestSerializer serializer]
|
||||
|
||||
NSMutableURLRequest *requst = [[AFJSONRequestSerializer serializer]
|
||||
requestWithMethod:@"POST" URLString:url parameters:param error:nil];
|
||||
requst.timeoutInterval = 10.f;
|
||||
[requst setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
|
|
@ -125,4 +126,7 @@
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@
|
|||
[self.view makeToastActivity:CSToastPositionCenter];
|
||||
|
||||
NSString *url = [NSString stringWithFormat:@"%@sys/v1/login",[GiGaServerConfig getMainUrl]];
|
||||
[GiGaNetManager userLoginrequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
|
||||
[GiGaNetManager userbodyRequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
|
||||
GILog(@"%@",resDic);
|
||||
[self.view hideToastActivity];
|
||||
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
|
||||
|
|
|
|||
|
|
@ -518,8 +518,16 @@
|
|||
#pragma mark 个人中心 action
|
||||
-(void)rightBtnAction{
|
||||
|
||||
GiGaMeViewController *meVC= [[GiGaMeViewController alloc] init];
|
||||
[self.navigationController pushViewController:meVC animated:YES];
|
||||
BOOL isUserLogin = [GiGaUserDefault isUserLogin];
|
||||
|
||||
if (isUserLogin) {
|
||||
GiGaMeViewController *meVC= [[GiGaMeViewController alloc] init];
|
||||
[self.navigationController pushViewController:meVC animated:YES];
|
||||
}else{
|
||||
GiGaUserLoginVC *userlogInVC= [[GiGaUserLoginVC alloc] init];
|
||||
GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC];
|
||||
[self presentViewController:baseNav animated:YES completion:nil];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,18 +13,27 @@
|
|||
#import "GIGaQuestionSlider.h"
|
||||
#import "MaskQuestionView.h"
|
||||
#import "ExercisesModel.h"
|
||||
#import "QustionAnswer.h"
|
||||
#import "GiGaServerConfig.h"
|
||||
|
||||
@interface GiGaQuestionVC ()
|
||||
@interface GiGaQuestionVC ()<QeustionViewDelegate>
|
||||
|
||||
@property (nonatomic,weak) MaskQuestionView *questionView;
|
||||
@property (nonatomic,assign) NSInteger page;
|
||||
@property (nonatomic,assign) NSInteger curentAnswerIdex;
|
||||
|
||||
@property (nonatomic,strong) NSMutableArray *questonArray;
|
||||
@property (nonatomic,strong) NSMutableArray *answerArray;
|
||||
|
||||
@property (nonatomic,strong) ExercisesModel *currentModel;
|
||||
|
||||
@property (nonatomic,strong) UILabel *questionlabel;
|
||||
@property (nonatomic,strong) UILabel *descLabel;
|
||||
@property (nonatomic,strong) UIButton *numberBtn;
|
||||
@property (nonatomic,strong) UIButton *nextBtn;
|
||||
@property (nonatomic,strong) UIButton *preBtn;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaQuestionVC
|
||||
|
|
@ -32,13 +41,31 @@
|
|||
- (void)viewDidLoad {
|
||||
[self addNavTitile:@"测试肤质"];
|
||||
[super viewDidLoad];
|
||||
|
||||
// self.title = @"测试肤质";
|
||||
_page = 1;
|
||||
//默认
|
||||
_curentAnswerIdex = 0;
|
||||
|
||||
//
|
||||
[self loadRequestQuestions];
|
||||
|
||||
//[self initUI];
|
||||
|
||||
}
|
||||
|
||||
-(NSMutableArray *)questonArray{
|
||||
if (!_questonArray) {
|
||||
_questonArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _questonArray;
|
||||
}
|
||||
|
||||
//questionId answerid
|
||||
|
||||
- (NSMutableArray *)answerArray{
|
||||
if (!_answerArray) {
|
||||
_answerArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _answerArray;
|
||||
}
|
||||
|
||||
-(void)initUI{
|
||||
|
|
@ -48,12 +75,14 @@
|
|||
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
|
||||
[numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
|
||||
self.numberBtn = numberBtn;
|
||||
[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.questionlabel = titleLabel;
|
||||
[self.view addSubview:titleLabel];
|
||||
|
||||
UILabel *descLabel = [[UILabel alloc] init];
|
||||
|
|
@ -62,7 +91,7 @@
|
|||
descLabel.textColor = GIGARGB(208, 208, 208, 1);
|
||||
descLabel.numberOfLines = 0;
|
||||
descLabel.textAlignment = NSTextAlignmentCenter;
|
||||
|
||||
self.descLabel = descLabel;
|
||||
[self.view addSubview:descLabel];
|
||||
|
||||
[numberBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
|
@ -87,52 +116,127 @@
|
|||
|
||||
}];
|
||||
|
||||
//测试题
|
||||
[self creatQustionView];
|
||||
|
||||
//下一题
|
||||
UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
nextBtn.backgroundColor = GIGARGB(181, 14, 14, 1);
|
||||
[nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
NSAttributedString *nextTitle = [[NSAttributedString alloc] initWithString:@"下一题" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
[nextBtn setAttributedTitle:nextTitle forState:UIControlStateNormal];
|
||||
nextBtn.layer.masksToBounds = YES;
|
||||
nextBtn.layer.cornerRadius = 2;
|
||||
self.nextBtn = nextBtn;
|
||||
[self.view addSubview:nextBtn];
|
||||
|
||||
[nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 - 126 /2);
|
||||
}];
|
||||
|
||||
|
||||
//上一题
|
||||
UIButton *preBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[preBtn addTarget:self action:@selector(preBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
NSAttributedString *preTitle = [[NSAttributedString alloc] initWithString:@"上一题" attributes:@{NSFontAttributeName:[UIFont fontWithName:GIGA_FONTBOLD size:18],NSForegroundColorAttributeName:GIGARGB(181, 14, 14, 1)}];
|
||||
[preBtn setAttributedTitle:preTitle forState:UIControlStateNormal];
|
||||
|
||||
preBtn.layer.borderWidth = 1;
|
||||
preBtn.layer.borderColor = GIGARGB(181, 14, 14, 1).CGColor;
|
||||
preBtn.layer.masksToBounds = YES;
|
||||
preBtn.layer.cornerRadius = 2;
|
||||
self.preBtn = preBtn;
|
||||
[self.view addSubview:self.preBtn];
|
||||
|
||||
[self.preBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(69);
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(97, 40));
|
||||
|
||||
}];
|
||||
|
||||
if (_page == 1) {
|
||||
self.preBtn.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)creatQustionView{
|
||||
|
||||
if (!_currentModel&&!_currentModel.optionsStyle) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentModel.optionsStyle == 1) {
|
||||
[self creatAnswerView:MaskQuetionViewStleSliderNormal];
|
||||
}else if (_currentModel.optionsStyle == 2){
|
||||
[self creatAnswerView:MaskQuetionViewStleYesOrNO];
|
||||
}else if (_currentModel.optionsStyle == 3 ){
|
||||
[self creatAnswerView:MaskQuetionViewStyleSliderShowIndicator];
|
||||
}else if (_currentModel.optionsStyle == 4){
|
||||
[self creatAnswerView:MaskQuetionViewStleSliderGradient];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-(void)creatAnswerView:(MaskQuetionViewStyle)style{
|
||||
|
||||
//选择题view
|
||||
NSArray *titles = @[@"hahah",@"呵呵呵呵",@"哦哦",@"有有u哟哦",@"呵呵呵呵"];
|
||||
NSArray *titles = @[@"title0",@"title1",@"title2",@"title3",@"title4"];
|
||||
NSMutableArray *tit = [NSMutableArray new];
|
||||
ExercisesModel *model = self.questonArray[0];
|
||||
NSArray *modeA = model.answerList;
|
||||
for (NSDictionary *mode in modeA){
|
||||
[tit addObject:mode[@"answer"]];
|
||||
|
||||
NSArray *answerList1 = _currentModel.answerList;
|
||||
for (QustionAnswer *mode in answerList1){
|
||||
//[tit insertObject:mode.answer atIndex:0];
|
||||
[tit addObject:mode.answer];
|
||||
}
|
||||
titles = tit;
|
||||
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:MaskQuetionViewStleSliderNormal titles:titles];
|
||||
if (self.questionView) {
|
||||
[self.questionView removeFromSuperview];
|
||||
self.questionView = nil;
|
||||
}
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
MaskQuestionView *questionView = [[MaskQuestionView alloc] initQuestionView:CGRectMake(0,248, self.view.frame.size.width,212) style:style titles:titles];
|
||||
questionView.answerList = _currentModel.answerList;
|
||||
NSLog(@"_currentModel--ID:%d",_currentModel.questionId);
|
||||
questionView.delegate = self;
|
||||
|
||||
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);
|
||||
|
||||
- (void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index
|
||||
{
|
||||
NSLog(@"答案下标:%ld",(long)index);
|
||||
_curentAnswerIdex = index;
|
||||
}
|
||||
|
||||
-(NSMutableArray *)questonArray{
|
||||
if (!_questonArray) {
|
||||
_questonArray = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return _questonArray;
|
||||
- (void)yesOrNoChoiceModelAt:(NSInteger)index{
|
||||
|
||||
_curentAnswerIdex = index;
|
||||
}
|
||||
|
||||
-(void)loadRequestQuestions{
|
||||
|
||||
NSDictionary *params = @{};
|
||||
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params];
|
||||
[self.view makeToastActivity:CSToastPositionCenter];
|
||||
|
||||
[request requstDataWithResult:^(GiGaAPIResult *result) {
|
||||
if (result.success) {
|
||||
|
||||
[self.view hideToastActivity];
|
||||
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.currentModel = self.questonArray[0];
|
||||
[self initUI];
|
||||
}
|
||||
}];
|
||||
|
|
@ -147,44 +251,106 @@
|
|||
}
|
||||
|
||||
#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(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
|
||||
//刷新问题相关数据
|
||||
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",(long)_page] attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
||||
|
||||
[_numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
|
||||
|
||||
self.questionlabel.text = [NSString stringWithFormat:@"%@",_currentModel.question];
|
||||
self.descLabel.text = _currentModel.remark;
|
||||
|
||||
//
|
||||
[self creatQustionView];
|
||||
|
||||
//next pre
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
if (_page > 1) {
|
||||
self.preBtn.hidden = NO;
|
||||
[self.nextBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 + 10);
|
||||
|
||||
}];
|
||||
|
||||
}else{
|
||||
|
||||
[self.nextBtn mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.view.mas_top).offset(529);
|
||||
make.size.mas_equalTo(CGSizeMake(126, 40));
|
||||
make.left.mas_equalTo(self.view.mas_left).offset(self.view.frame.size.width /2 - 126 /2);
|
||||
}];
|
||||
self.preBtn.hidden = YES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)nextBtnAction{
|
||||
// if (_page == [_currentModel.totalCount integerValue] ) {
|
||||
// GIGA_ShowToast(@"没有了");
|
||||
// return;
|
||||
// }
|
||||
// [self saveProgress];
|
||||
// _page ++ ;
|
||||
// //获取题目信息
|
||||
// [self getQuestionsInfo];
|
||||
[self saveProgress];
|
||||
|
||||
if (_page == self.questonArray.count ) {
|
||||
GIGA_ShowToast(@"没有了");
|
||||
[self submitAnswer];
|
||||
return;
|
||||
}
|
||||
|
||||
_page ++ ;
|
||||
|
||||
//获取题目信息
|
||||
[self getQuestionsInfo];
|
||||
|
||||
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES;
|
||||
|
||||
}
|
||||
|
||||
-(void)submitAnswer{
|
||||
|
||||
NSDictionary *params = @{@"singleChoiceList":self.answerArray};
|
||||
[self.view makeToastActivity:CSToastPositionCenter];
|
||||
NSString *url = [NSString stringWithFormat:@"%@activity/maskquestion/v1/result",[GiGaServerConfig getMainUrl]];
|
||||
|
||||
[GiGaNetManager userbodyRequest:url params:params completionHandler:^(NSURLResponse *response, NSDictionary *resDic, NSError * _Nullable error) {
|
||||
[self.view hideToastActivity];
|
||||
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];
|
||||
GILog(@"**答案提交***\n code:%ld\n message:%@\n *******\n dic:%@",result.code,result.message,result.dic);
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)preBtnAction{
|
||||
|
||||
_page -- ;
|
||||
//获取题目信息
|
||||
[self getQuestionsInfo];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -做题记录
|
||||
-(void)saveProgress{
|
||||
// NSString *answer = self.questionView.selectAnswer;
|
||||
// NSString *anserNum = self.questionView.qrnum;
|
||||
// NSString *anserid = _currentModel.questionid;
|
||||
// GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid);
|
||||
|
||||
int questionId = _currentModel.questionId;
|
||||
QustionAnswer *curentAnswer = _currentModel.answerList[_curentAnswerIdex];
|
||||
int answerid = curentAnswer.answer_id;
|
||||
|
||||
GILog(@"问题ID:%d\n 角标id(答案号):%d\n 题号:%ld",questionId,answerid,(long)_page);
|
||||
NSDictionary *answerDic = @{@"questionId":[NSString stringWithFormat:@"%d",questionId],@"answerId":[NSString stringWithFormat:@"%d",answerid]};
|
||||
for (NSDictionary *dic in self.answerArray) {
|
||||
// 返回时覆盖
|
||||
if (questionId == [dic[@"questionId"] intValue]) {
|
||||
//先删除再添加 上传测试结果顺序任意
|
||||
[self.answerArray removeObject:dic];
|
||||
}
|
||||
}
|
||||
|
||||
[self.answerArray addObject:answerDic];
|
||||
|
||||
NSLog(@"选择题答案:%@",self.answerArray);
|
||||
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
|
|
@ -192,6 +358,4 @@
|
|||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -7,31 +7,22 @@
|
|||
//
|
||||
|
||||
#import <JSONModel/JSONModel.h>
|
||||
#import "QustionAnswer.h"
|
||||
|
||||
//内层模型
|
||||
//@protocol QustionAnswer//内层模型协议
|
||||
//@end
|
||||
@class QustionAnswer;
|
||||
|
||||
@interface QustionAnswer:JSONModel
|
||||
@property (nonatomic,copy) NSString *answer;
|
||||
@property (nonatomic,assign) int bsjz;
|
||||
@property (nonatomic,copy) NSString *createTime;
|
||||
@property (nonatomic,assign) int dryness;
|
||||
@property (nonatomic,assign) int fx;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
//外层模型
|
||||
@interface ExercisesModel : JSONModel
|
||||
@protocol QustionAnswer;//内层模型协议;
|
||||
|
||||
@property (nonatomic,strong) NSMutableArray<QustionAnswer *>* answerList;
|
||||
@interface ExercisesModel : JSONModel
|
||||
@property (nonatomic,strong) NSArray<QustionAnswer>* answerList;
|
||||
@property (nonatomic,assign) int questionType;
|
||||
//排序
|
||||
@property (nonatomic,assign) int sortNum;
|
||||
@property (nonatomic,copy) NSString *remark;
|
||||
@property (nonatomic,copy) NSString *question;
|
||||
//optionsStyle:样式(单选或滑动) 1滑动,2单选 ,3滑动带指示 ,4滑动渐变,
|
||||
@property (nonatomic,assign) int optionsStyle;
|
||||
@property (nonatomic,assign) int questionId;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,14 @@
|
|||
#import "ExercisesModel.h"
|
||||
|
||||
@implementation ExercisesModel
|
||||
//+(JSONKeyMapper *)keyMapper{
|
||||
// return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"id":@"answer_id"}];
|
||||
//}
|
||||
|
||||
+(JSONKeyMapper *)keyMapper{
|
||||
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"questionId":@"id"}];
|
||||
}
|
||||
|
||||
+ (BOOL)propertyIsOptional:(NSString *)propertyName{
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// QustionAnswer.h
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/9/12.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <JSONModel/JSONModel.h>
|
||||
|
||||
@interface QustionAnswer : JSONModel
|
||||
@property (nonatomic,copy) NSString *answer;
|
||||
@property (nonatomic,assign) int bsjz;
|
||||
@property (nonatomic,copy) NSString *createTime;
|
||||
@property (nonatomic,assign) int dryness;
|
||||
@property (nonatomic,assign) int fx;
|
||||
@property (nonatomic,assign) int answer_id;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// QustionAnswer.m
|
||||
// GIGA
|
||||
//
|
||||
// Created by lianxiang on 2018/9/12.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QustionAnswer.h"
|
||||
|
||||
@implementation QustionAnswer
|
||||
|
||||
+(JSONKeyMapper *)keyMapper{
|
||||
|
||||
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{@"answer_id":@"id"}];
|
||||
|
||||
}
|
||||
|
||||
+ (BOOL)propertyIsOptional:(NSString *)propertyName{
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -11,11 +11,11 @@ typedef NS_ENUM(NSInteger,GIGaQuestionSliderType)
|
|||
{
|
||||
GIGaQuestionSliderTypeGray = 0,//灰
|
||||
GIGaQuestionSliderTypeGradient ,//变色
|
||||
|
||||
|
||||
GIGaQuestionSliderTypeIndicator //带指示器
|
||||
};
|
||||
|
||||
@interface GIGaQuestionSlider : UISlider
|
||||
- (instancetype)initWithFrame:(CGRect)frame type:(GIGaQuestionSliderType)type;
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@
|
|||
self.minimumValue = 0.0;
|
||||
self.maximumValue = 1.0;
|
||||
self.value = 0.5;
|
||||
|
||||
|
||||
[self creatSubView:type];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
-(void)creatSubView:(GIGaQuestionSliderType)type{
|
||||
|
|
@ -37,12 +38,14 @@
|
|||
{
|
||||
[self createUI];
|
||||
}
|
||||
|
||||
break;
|
||||
case GIGaQuestionSliderTypeGradient:
|
||||
{
|
||||
[self creatGradient];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -70,8 +73,6 @@
|
|||
[self.layer addSublayer:gradientLayer];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)createUI{
|
||||
|
||||
self.minimumValue = 0.0;
|
||||
|
|
@ -82,6 +83,7 @@
|
|||
|
||||
}
|
||||
|
||||
|
||||
-(CGRect)trackRectForBounds:(CGRect)bounds
|
||||
{
|
||||
bounds.origin.x = bounds.origin.x;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="GiGaAnswerViewCell" id="KGk-i7-Jjw" customClass="GiGaAnswerViewCell">
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="GiGaAnswerViewCell" id="KGk-i7-Jjw" customClass="GiGaAnswerViewCell">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
|
||||
|
|
|
|||
|
|
@ -11,13 +11,23 @@
|
|||
typedef NS_ENUM(NSInteger,MaskQuetionViewStyle)
|
||||
{
|
||||
MaskQuetionViewStleSliderNormal = 0,// 滑块正常
|
||||
MaskQuetionViewStleSliderGradient ,//滑块变色
|
||||
MaskQuetionViewStleYesOrNO // 是 否
|
||||
MaskQuetionViewStleSliderGradient =1 ,//滑块变色
|
||||
MaskQuetionViewStleYesOrNO =2, // 是 否
|
||||
MaskQuetionViewStyleSliderShowIndicator =3,//滑动带指示器
|
||||
|
||||
};
|
||||
|
||||
@protocol QeustionViewDelegate<NSObject>;
|
||||
@optional
|
||||
-(void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index;
|
||||
-(void)yesOrNoChoiceModelAt:(NSInteger)index;
|
||||
@end
|
||||
|
||||
@interface MaskQuestionView : UIView
|
||||
@property(nonatomic,assign) MaskQuetionViewStyle *style;
|
||||
|
||||
@property(nonatomic,assign) id<QeustionViewDelegate>delegate;
|
||||
@property(nonatomic,assign) MaskQuetionViewStyle style;
|
||||
@property(nonatomic,strong) NSArray *answerList;
|
||||
|
||||
-(instancetype)initQuestionView:(CGRect)frame style:(MaskQuetionViewStyle)style titles:(NSArray *)titles;
|
||||
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// NYPopover.h
|
||||
// NYReader
|
||||
//
|
||||
// Created by Cassius Pacheco on 21/12/12.
|
||||
// Copyright (c) 2012 Nyvra Software. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface NYPopover : UIView
|
||||
|
||||
@property (nonatomic, strong) UILabel *textLabel;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
//
|
||||
// NYPopover.m
|
||||
// NYReader
|
||||
//
|
||||
// Created by Cassius Pacheco on 21/12/12.
|
||||
// Copyright (c) 2012 Nyvra Software. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NYPopover.h"
|
||||
|
||||
@implementation NYPopover
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
|
||||
self.textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
self.textLabel.backgroundColor = [UIColor clearColor];
|
||||
self.textLabel.textColor = [UIColor whiteColor];
|
||||
self.textLabel.font = [UIFont boldSystemFontOfSize:13];
|
||||
self.textLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.textLabel.adjustsFontSizeToFitWidth = YES;
|
||||
self.opaque = NO;
|
||||
|
||||
[self addSubview:self.textLabel];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
[super setFrame:frame];
|
||||
|
||||
CGFloat y = (frame.size.height - 26) / 3;
|
||||
|
||||
if (frame.size.height < 38)
|
||||
y = 0;
|
||||
|
||||
self.textLabel.frame = CGRectMake(0, y, frame.size.width, 26);
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)rect
|
||||
{
|
||||
//// General Declarations
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
//// Color Declarations
|
||||
UIColor* gradientColor = [UIColor colorWithRed: 0.267 green: 0.303 blue: 0.335 alpha: 1];
|
||||
UIColor* gradientColor2 = [UIColor colorWithRed: 0.04 green: 0.04 blue: 0.04 alpha: 1];
|
||||
UIColor* shadowColor2 = [UIColor colorWithRed: 0.524 green: 0.553 blue: 0.581 alpha: 0.3];
|
||||
|
||||
//// Gradient Declarations
|
||||
NSArray* gradientColors = [NSArray arrayWithObjects:
|
||||
(id)gradientColor.CGColor,
|
||||
(id)gradientColor2.CGColor, nil];
|
||||
CGFloat gradientLocations[] = {0, 1};
|
||||
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations);
|
||||
|
||||
//// Shadow Declarations
|
||||
UIColor* innerShadow = shadowColor2;
|
||||
CGSize innerShadowOffset = CGSizeMake(0, 1.5);
|
||||
CGFloat innerShadowBlurRadius = 0.5;
|
||||
|
||||
//// Frames
|
||||
CGRect frame = self.bounds;
|
||||
|
||||
//// Subframes
|
||||
CGRect frame2 = CGRectMake(CGRectGetMinX(frame) + floor((CGRectGetWidth(frame) - 11) * 0.51724 + 0.5), CGRectGetMinY(frame) + CGRectGetHeight(frame) - 9, 11, 9);
|
||||
|
||||
|
||||
//// Bezier Drawing
|
||||
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
|
||||
[bezierPath moveToPoint: CGPointMake(CGRectGetMaxX(frame) - 0.5, CGRectGetMinY(frame) + 4.5)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMaxX(frame) - 0.5, CGRectGetMaxY(frame) - 11.5)];
|
||||
[bezierPath addCurveToPoint: CGPointMake(CGRectGetMaxX(frame) - 4.5, CGRectGetMaxY(frame) - 7.5) controlPoint1: CGPointMake(CGRectGetMaxX(frame) - 0.5, CGRectGetMaxY(frame) - 9.29) controlPoint2: CGPointMake(CGRectGetMaxX(frame) - 2.29, CGRectGetMaxY(frame) - 7.5)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame2) + 10.64, CGRectGetMinY(frame2) + 1.5)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame2) + 5.5, CGRectGetMinY(frame2) + 8)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame2) + 0.36, CGRectGetMinY(frame2) + 1.5)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 4.5, CGRectGetMaxY(frame) - 7.5)];
|
||||
[bezierPath addCurveToPoint: CGPointMake(CGRectGetMinX(frame) + 0.5, CGRectGetMaxY(frame) - 11.5) controlPoint1: CGPointMake(CGRectGetMinX(frame) + 2.29, CGRectGetMaxY(frame) - 7.5) controlPoint2: CGPointMake(CGRectGetMinX(frame) + 0.5, CGRectGetMaxY(frame) - 9.29)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMinX(frame) + 0.5, CGRectGetMinY(frame) + 4.5)];
|
||||
[bezierPath addCurveToPoint: CGPointMake(CGRectGetMinX(frame) + 4.5, CGRectGetMinY(frame) + 0.5) controlPoint1: CGPointMake(CGRectGetMinX(frame) + 0.5, CGRectGetMinY(frame) + 2.29) controlPoint2: CGPointMake(CGRectGetMinX(frame) + 2.29, CGRectGetMinY(frame) + 0.5)];
|
||||
[bezierPath addLineToPoint: CGPointMake(CGRectGetMaxX(frame) - 4.5, CGRectGetMinY(frame) + 0.5)];
|
||||
[bezierPath addCurveToPoint: CGPointMake(CGRectGetMaxX(frame) - 0.5, CGRectGetMinY(frame) + 4.5) controlPoint1: CGPointMake(CGRectGetMaxX(frame) - 2.29, CGRectGetMinY(frame) + 0.5) controlPoint2: CGPointMake(CGRectGetMaxX(frame) - 0.5, CGRectGetMinY(frame) + 2.29)];
|
||||
[bezierPath closePath];
|
||||
CGContextSaveGState(context);
|
||||
[bezierPath addClip];
|
||||
CGRect bezierBounds = bezierPath.bounds;
|
||||
CGContextDrawLinearGradient(context, gradient,
|
||||
CGPointMake(CGRectGetMidX(bezierBounds), CGRectGetMinY(bezierBounds)),
|
||||
CGPointMake(CGRectGetMidX(bezierBounds), CGRectGetMaxY(bezierBounds)),
|
||||
0);
|
||||
CGContextRestoreGState(context);
|
||||
|
||||
////// Bezier Inner Shadow
|
||||
CGRect bezierBorderRect = CGRectInset([bezierPath bounds], -innerShadowBlurRadius, -innerShadowBlurRadius);
|
||||
bezierBorderRect = CGRectOffset(bezierBorderRect, -innerShadowOffset.width, -innerShadowOffset.height);
|
||||
bezierBorderRect = CGRectInset(CGRectUnion(bezierBorderRect, [bezierPath bounds]), -1, -1);
|
||||
|
||||
UIBezierPath* bezierNegativePath = [UIBezierPath bezierPathWithRect: bezierBorderRect];
|
||||
[bezierNegativePath appendPath: bezierPath];
|
||||
bezierNegativePath.usesEvenOddFillRule = YES;
|
||||
|
||||
CGContextSaveGState(context);
|
||||
{
|
||||
CGFloat xOffset = innerShadowOffset.width + round(bezierBorderRect.size.width);
|
||||
CGFloat yOffset = innerShadowOffset.height;
|
||||
CGContextSetShadowWithColor(context,
|
||||
CGSizeMake(xOffset + copysign(0.1, xOffset), yOffset + copysign(0.1, yOffset)),
|
||||
innerShadowBlurRadius,
|
||||
innerShadow.CGColor);
|
||||
|
||||
[bezierPath addClip];
|
||||
CGAffineTransform transform = CGAffineTransformMakeTranslation(-round(bezierBorderRect.size.width), 0);
|
||||
[bezierNegativePath applyTransform: transform];
|
||||
[[UIColor grayColor] setFill];
|
||||
[bezierNegativePath fill];
|
||||
}
|
||||
CGContextRestoreGState(context);
|
||||
|
||||
[[UIColor blackColor] setStroke];
|
||||
bezierPath.lineWidth = 1;
|
||||
[bezierPath stroke];
|
||||
|
||||
|
||||
//// Cleanup
|
||||
CGGradientRelease(gradient);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// NYSliderPopover.h
|
||||
// NYReader
|
||||
//
|
||||
// Created by Cassius Pacheco on 21/12/12.
|
||||
// Copyright (c) 2012 Nyvra Software. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "NYPopover.h"
|
||||
|
||||
@interface NYSliderPopover : UISlider
|
||||
|
||||
@property (nonatomic, strong) NYPopover *popover;
|
||||
|
||||
- (void)showPopover;
|
||||
- (void)showPopoverAnimated:(BOOL)animated;
|
||||
- (void)hidePopover;
|
||||
- (void)hidePopoverAnimated:(BOOL)animated;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
//
|
||||
// NYSliderPopover.m
|
||||
// NYReader
|
||||
//
|
||||
// Created by Cassius Pacheco on 21/12/12.
|
||||
// Copyright (c) 2012 Nyvra Software. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NYSliderPopover.h"
|
||||
#import "NYPopover.h"
|
||||
|
||||
@implementation NYSliderPopover
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark UISlider methods
|
||||
|
||||
- (NYPopover *)popover
|
||||
{
|
||||
if (_popover == nil) {
|
||||
//Default size, can be changed after
|
||||
[self addTarget:self action:@selector(updatePopoverFrame) forControlEvents:UIControlEventValueChanged];
|
||||
_popover = [[NYPopover alloc] initWithFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y - 32, 40, 32)];
|
||||
[self updatePopoverFrame];
|
||||
_popover.alpha = 0;
|
||||
[self.superview addSubview:_popover];
|
||||
|
||||
[self thumbimageView];
|
||||
[self createUI];
|
||||
}
|
||||
|
||||
return _popover;
|
||||
}
|
||||
|
||||
- (void)setValue:(float)value
|
||||
{
|
||||
[super setValue:value];
|
||||
[self updatePopoverFrame];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[self updatePopoverFrame];
|
||||
[self showPopoverAnimated:YES];
|
||||
[super touchesBegan:touches withEvent:event];
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[self hidePopoverAnimated:YES];
|
||||
[super touchesEnded:touches withEvent:event];
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[self hidePopoverAnimated:YES];
|
||||
[super touchesCancelled:touches withEvent:event];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark - Popover methods
|
||||
|
||||
- (void)updatePopoverFrame
|
||||
{
|
||||
//Inspired in Collin Ruffenach's ELCSlider https://github.com/elc/ELCSlider/blob/master/ELCSlider/ELCSlider.m#L53
|
||||
|
||||
CGFloat minimum = self.minimumValue;
|
||||
CGFloat maximum = self.maximumValue;
|
||||
CGFloat value = self.value;
|
||||
|
||||
if (minimum < 0.0) {
|
||||
|
||||
value = self.value - minimum;
|
||||
maximum = maximum - minimum;
|
||||
minimum = 0.0;
|
||||
}
|
||||
|
||||
CGFloat x = self.frame.origin.x;
|
||||
CGFloat maxMin = (maximum + minimum) / 2.0;
|
||||
|
||||
x += (((value - minimum) / (maximum - minimum)) * self.frame.size.width) - (self.popover.frame.size.width / 2.0);
|
||||
|
||||
if (value > maxMin) {
|
||||
|
||||
value = (value - maxMin) + (minimum * 1.0);
|
||||
value = value / maxMin;
|
||||
value = value * 11.0;
|
||||
|
||||
x = x - value;
|
||||
|
||||
} else {
|
||||
|
||||
value = (maxMin - value) + (minimum * 1.0);
|
||||
value = value / maxMin;
|
||||
value = value * 11.0;
|
||||
|
||||
x = x + value;
|
||||
}
|
||||
|
||||
CGRect popoverRect = self.popover.frame;
|
||||
popoverRect.origin.x = x;
|
||||
popoverRect.origin.y = self.frame.origin.y - popoverRect.size.height - 1;
|
||||
|
||||
self.popover.frame = popoverRect;
|
||||
}
|
||||
|
||||
- (void)showPopover
|
||||
{
|
||||
[self showPopoverAnimated:NO];
|
||||
}
|
||||
|
||||
- (void)showPopoverAnimated:(BOOL)animated
|
||||
{
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.popover.alpha = 1.0;
|
||||
}];
|
||||
} else {
|
||||
self.popover.alpha = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hidePopover
|
||||
{
|
||||
[self hidePopoverAnimated:NO];
|
||||
}
|
||||
|
||||
- (void)hidePopoverAnimated:(BOOL)animated
|
||||
{
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.popover.alpha = 0;
|
||||
}];
|
||||
} else {
|
||||
self.popover.alpha = 0;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)createUI{
|
||||
|
||||
self.minimumValue = 0.0;
|
||||
self.maximumValue = 1.0;
|
||||
self.value = 0.5;
|
||||
self.minimumTrackTintColor = GIGARGB(216,216, 216, 1);
|
||||
self.maximumTrackTintColor = GIGARGB(216,216, 216, 1);
|
||||
|
||||
}
|
||||
|
||||
-(CGRect)trackRectForBounds:(CGRect)bounds
|
||||
{
|
||||
bounds.origin.x = bounds.origin.x;
|
||||
bounds.origin.y = bounds.origin.y;
|
||||
bounds.size.height = bounds.size.height;
|
||||
bounds.size.width = bounds.size.width;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
-(void)thumbimageView{
|
||||
|
||||
[self setThumbImage:[self OriginImage:[UIImage imageNamed:@"btn_slider_thumb"] scaleToSize:CGSizeMake(40, 40)] forState:UIControlStateNormal];
|
||||
[self setThumbImage:[self OriginImage:[UIImage imageNamed:@"btn_slider_thumb"] scaleToSize:CGSizeMake(40, 40)] forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
-(UIImage*) OriginImage:(UIImage*)image scaleToSize:(CGSize)size
|
||||
|
||||
{
|
||||
UIGraphicsBeginImageContext(size);//size为CGSize类型,即你所需要的图片尺寸
|
||||
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
|
||||
|
||||
UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
|
||||
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return scaledImage;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Reference in New Issue