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

View File

@ -106,6 +106,9 @@
83A22718212ABDFF00B3E75C /* GiGaBlockButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22717212ABDFF00B3E75C /* GiGaBlockButton.m */; }; 83A22718212ABDFF00B3E75C /* GiGaBlockButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22717212ABDFF00B3E75C /* GiGaBlockButton.m */; };
83A2271F212AC8C100B3E75C /* GiGaUserLoginVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A2271D212AC8C100B3E75C /* GiGaUserLoginVC.m */; }; 83A2271F212AC8C100B3E75C /* GiGaUserLoginVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A2271D212AC8C100B3E75C /* GiGaUserLoginVC.m */; };
83A22720212AC8C100B3E75C /* GiGaUserLoginVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83A2271E212AC8C100B3E75C /* GiGaUserLoginVC.xib */; }; 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 */; }; 83BDC0582147B89900E74E0D /* GiGaAnswerViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BDC0562147B89900E74E0D /* GiGaAnswerViewCell.m */; };
83BDC0592147B89900E74E0D /* GiGaAnswerViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83BDC0572147B89900E74E0D /* GiGaAnswerViewCell.xib */; }; 83BDC0592147B89900E74E0D /* GiGaAnswerViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 83BDC0572147B89900E74E0D /* GiGaAnswerViewCell.xib */; };
83BFAE67213CCF10004EF801 /* GiGaMineUserViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BFAE65213CCF10004EF801 /* GiGaMineUserViewCell.m */; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 83BDC0572147B89900E74E0D /* GiGaAnswerViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GiGaAnswerViewCell.xib; sourceTree = "<group>"; };
@ -865,6 +874,8 @@
83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */, 83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */,
83773FBA214769230014EE4C /* ExercisesModel.h */, 83773FBA214769230014EE4C /* ExercisesModel.h */,
83773FBB214769230014EE4C /* ExercisesModel.m */, 83773FBB214769230014EE4C /* ExercisesModel.m */,
83BC8A882148D28300820437 /* QustionAnswer.h */,
83BC8A892148D28300820437 /* QustionAnswer.m */,
); );
path = Model; path = Model;
sourceTree = "<group>"; sourceTree = "<group>";
@ -872,6 +883,7 @@
83835BC0212E66A1001480F2 /* View */ = { 83835BC0212E66A1001480F2 /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
83BC8A812148BE8A00820437 /* NYSliderPopover */,
83835BC8212E8045001480F2 /* GIGAQuetionView.h */, 83835BC8212E8045001480F2 /* GIGAQuetionView.h */,
83835BC9212E8045001480F2 /* GIGAQuetionView.m */, 83835BC9212E8045001480F2 /* GIGAQuetionView.m */,
83773FBD214791E10014EE4C /* GIGaQuestionSlider.h */, 83773FBD214791E10014EE4C /* GIGaQuestionSlider.h */,
@ -985,6 +997,17 @@
path = Controller; path = Controller;
sourceTree = "<group>"; 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 */ = { 83E40B2C21218B7E008149C4 /* LogIn */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -1263,12 +1286,15 @@
83BFAE7B213D3F3A004EF801 /* MaskTimeCircularProgressView.m in Sources */, 83BFAE7B213D3F3A004EF801 /* MaskTimeCircularProgressView.m in Sources */,
8314D2112133ABE500B458BF /* WeiIXinApiManager.m in Sources */, 8314D2112133ABE500B458BF /* WeiIXinApiManager.m in Sources */,
83BDC0582147B89900E74E0D /* GiGaAnswerViewCell.m in Sources */, 83BDC0582147B89900E74E0D /* GiGaAnswerViewCell.m in Sources */,
83BC8A862148BE8A00820437 /* NYSliderPopover.m in Sources */,
83773FC52147A5CC0014EE4C /* MaskQuestionView.m in Sources */, 83773FC52147A5CC0014EE4C /* MaskQuestionView.m in Sources */,
83835BCA212E8045001480F2 /* GIGAQuetionView.m in Sources */, 83835BCA212E8045001480F2 /* GIGAQuetionView.m in Sources */,
8361B3CE212155C200238FEB /* ViewController.m in Sources */, 8361B3CE212155C200238FEB /* ViewController.m in Sources */,
8361B4382121847600238FEB /* UINavigationBar+Custom.m in Sources */, 8361B4382121847600238FEB /* UINavigationBar+Custom.m in Sources */,
83BFAE6C213CD0E3004EF801 /* GiGaMineInfoViewCell.m in Sources */, 83BFAE6C213CD0E3004EF801 /* GiGaMineInfoViewCell.m in Sources */,
83BC8A872148BE8A00820437 /* NYPopover.m in Sources */,
83346AD4212BFF6E0054D597 /* UserGuardViewController.m in Sources */, 83346AD4212BFF6E0054D597 /* UserGuardViewController.m in Sources */,
83BC8A8A2148D28300820437 /* QustionAnswer.m in Sources */,
8357ADC92123BFCA000816F2 /* GiGaUserManager.m in Sources */, 8357ADC92123BFCA000816F2 /* GiGaUserManager.m in Sources */,
83835BB3212E50ED001480F2 /* ActiveMesagelistVC.m in Sources */, 83835BB3212E50ED001480F2 /* ActiveMesagelistVC.m in Sources */,
83835BC3212E677C001480F2 /* GiGaQuestionVC.m in Sources */, 83835BC3212E677C001480F2 /* GiGaQuestionVC.m in Sources */,

View File

@ -2,22 +2,4 @@
<Bucket <Bucket
type = "0" type = "0"
version = "2.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> </Bucket>

View File

@ -22,6 +22,7 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
//[self.navigationController.navigationBar cnSetBackgroundColor:GIGARGB(216, 216, 216, 1)]; //[self.navigationController.navigationBar cnSetBackgroundColor:GIGARGB(216, 216, 216, 1)];

View File

@ -18,7 +18,10 @@ typedef void (^responseBlock)(NSDictionary *responseDict, NSDictionary *response
+(void)request:(NSString *)url params:(NSDictionary *)param +(void)request:(NSString *)url params:(NSDictionary *)param
success:(void (^)(id response))success success:(void (^)(id response))success
failure:(void (^)(NSError *err))failure; 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 @end

View File

@ -98,13 +98,14 @@
} }
//body //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]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]]; NSURL *baseUrl = [NSURL URLWithString:[GiGaServerConfig getMainUrl]];
AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration]; AFHTTPSessionManager*manager=[[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:configuration];
NSMutableURLRequest *requst = [[AFJSONRequestSerializer serializer]
NSMutableURLRequest *requst = [[AFJSONRequestSerializer serializer]
requestWithMethod:@"POST" URLString:url parameters:param error:nil]; requestWithMethod:@"POST" URLString:url parameters:param error:nil];
requst.timeoutInterval = 10.f; requst.timeoutInterval = 10.f;
[requst setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [requst setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
@ -125,4 +126,7 @@
} }
@end @end

View File

@ -200,7 +200,7 @@
[self.view makeToastActivity:CSToastPositionCenter]; [self.view makeToastActivity:CSToastPositionCenter];
NSString *url = [NSString stringWithFormat:@"%@sys/v1/login",[GiGaServerConfig getMainUrl]]; 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); GILog(@"%@",resDic);
[self.view hideToastActivity]; [self.view hideToastActivity];
GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic]; GiGaAPIResult *result = [[GiGaAPIResult alloc] initWithDictionary:resDic];

View File

@ -518,8 +518,16 @@
#pragma mark action #pragma mark action
-(void)rightBtnAction{ -(void)rightBtnAction{
GiGaMeViewController *meVC= [[GiGaMeViewController alloc] init]; BOOL isUserLogin = [GiGaUserDefault isUserLogin];
[self.navigationController pushViewController:meVC animated:YES];
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];
}
} }

View File

@ -13,18 +13,27 @@
#import "GIGaQuestionSlider.h" #import "GIGaQuestionSlider.h"
#import "MaskQuestionView.h" #import "MaskQuestionView.h"
#import "ExercisesModel.h" #import "ExercisesModel.h"
#import "QustionAnswer.h"
#import "GiGaServerConfig.h"
@interface GiGaQuestionVC () @interface GiGaQuestionVC ()<QeustionViewDelegate>
@property (nonatomic,weak) MaskQuestionView *questionView; @property (nonatomic,weak) MaskQuestionView *questionView;
@property (nonatomic,assign) NSInteger page; @property (nonatomic,assign) NSInteger page;
@property (nonatomic,assign) NSInteger curentAnswerIdex;
@property (nonatomic,strong) NSMutableArray *questonArray; @property (nonatomic,strong) NSMutableArray *questonArray;
@property (nonatomic,strong) NSMutableArray *answerArray;
@property (nonatomic,strong) ExercisesModel *currentModel; @property (nonatomic,strong) ExercisesModel *currentModel;
@property (nonatomic,strong) UILabel *questionlabel; @property (nonatomic,strong) UILabel *questionlabel;
@property (nonatomic,strong) UILabel *descLabel;
@property (nonatomic,strong) UIButton *numberBtn;
@property (nonatomic,strong) UIButton *nextBtn; @property (nonatomic,strong) UIButton *nextBtn;
@property (nonatomic,strong) UIButton *preBtn; @property (nonatomic,strong) UIButton *preBtn;
@end @end
@implementation GiGaQuestionVC @implementation GiGaQuestionVC
@ -32,13 +41,31 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[self addNavTitile:@"测试肤质"]; [self addNavTitile:@"测试肤质"];
[super viewDidLoad]; [super viewDidLoad];
// self.title = @"测试肤质"; // self.title = @"测试肤质";
_page = 1; _page = 1;
//
_curentAnswerIdex = 0;
// //
[self loadRequestQuestions]; [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{ -(void)initUI{
@ -48,12 +75,14 @@
NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}]; NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:@"1" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal]; [numberBtn setAttributedTitle:numbertitle forState:UIControlStateNormal];
self.numberBtn = numberBtn;
[self.view addSubview:numberBtn]; [self.view addSubview:numberBtn];
UILabel *titleLabel = [[UILabel alloc] init]; UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"悄悄地告诉你小优的年龄区间是?"; titleLabel.text = @"悄悄地告诉你小优的年龄区间是?";
titleLabel.font = [UIFont fontWithName:GIGA_FONTBOLD size:16]; titleLabel.font = [UIFont fontWithName:GIGA_FONTBOLD size:16];
titleLabel.textColor = GIGARGB(63, 63, 63, 1); titleLabel.textColor = GIGARGB(63, 63, 63, 1);
self.questionlabel = titleLabel;
[self.view addSubview:titleLabel]; [self.view addSubview:titleLabel];
UILabel *descLabel = [[UILabel alloc] init]; UILabel *descLabel = [[UILabel alloc] init];
@ -62,7 +91,7 @@
descLabel.textColor = GIGARGB(208, 208, 208, 1); descLabel.textColor = GIGARGB(208, 208, 208, 1);
descLabel.numberOfLines = 0; descLabel.numberOfLines = 0;
descLabel.textAlignment = NSTextAlignmentCenter; descLabel.textAlignment = NSTextAlignmentCenter;
self.descLabel = descLabel;
[self.view addSubview:descLabel]; [self.view addSubview:descLabel];
[numberBtn mas_makeConstraints:^(MASConstraintMaker *make) { [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 //view
NSArray *titles = @[@"hahah",@"呵呵呵呵",@"哦哦",@"有有u哟哦",@"呵呵呵呵"]; NSArray *titles = @[@"title0",@"title1",@"title2",@"title3",@"title4"];
NSMutableArray *tit = [NSMutableArray new]; NSMutableArray *tit = [NSMutableArray new];
ExercisesModel *model = self.questonArray[0];
NSArray *modeA = model.answerList; NSArray *answerList1 = _currentModel.answerList;
for (NSDictionary *mode in modeA){ for (QustionAnswer *mode in answerList1){
[tit addObject:mode[@"answer"]]; //[tit insertObject:mode.answer atIndex:0];
[tit addObject:mode.answer];
} }
titles = tit; 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.view addSubview:questionView];
self.questionView = questionView; self.questionView = questionView;
} }
-(void)updateValue:(UISlider *)slider{ - (void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index
NSLog(@"value%f",slider.value); {
GILog(@"formatvalue:%.2f",slider.value*60); NSLog(@"答案下标:%ld",(long)index);
_curentAnswerIdex = index;
} }
-(NSMutableArray *)questonArray{ - (void)yesOrNoChoiceModelAt:(NSInteger)index{
if (!_questonArray) {
_questonArray = [[NSMutableArray alloc] init]; _curentAnswerIdex = index;
}
return _questonArray;
} }
-(void)loadRequestQuestions{ -(void)loadRequestQuestions{
NSDictionary *params = @{}; NSDictionary *params = @{};
GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params]; GiGaBaseAPiRequest *request = [GiGaBaseAPiRequest initWithRequestPath:@"activity/maskquestion/v1/list" method:RequestPostMethod parms:params];
[self.view makeToastActivity:CSToastPositionCenter];
[request requstDataWithResult:^(GiGaAPIResult *result) { [request requstDataWithResult:^(GiGaAPIResult *result) {
if (result.success) { if (result.success) {
[self.view hideToastActivity];
NSLog(@"result:%@",result.dic); NSLog(@"result:%@",result.dic);
NSArray *list = result.dic[@"list"]; NSArray *list = result.dic[@"list"];
NSDictionary *answer = list[0];
for (NSDictionary *answerDic in list) { for (NSDictionary *answerDic in list) {
ExercisesModel *model = [[ExercisesModel alloc] initWithDictionary:answerDic error:nil]; ExercisesModel *model = [[ExercisesModel alloc] initWithDictionary:answerDic error:nil];
[self.questonArray addObject:model]; [self.questonArray addObject:model];
} }
self.currentModel = self.questonArray[0];
[self initUI]; [self initUI];
} }
}]; }];
@ -147,44 +251,106 @@
} }
#pragma mark #pragma mark
-(void)reloadViews{ -(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];// //
// // NSAttributedString *numbertitle = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",(long)_page] attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
// [_questionView reloadViewWithFrame:CGRectMake(30, CGRectGetMaxY(_questionlabel.frame) + 15, KMainW - 30*2, 0) style:[_currentModel.questiontype intValue] - 1 answerArray:_currentModel.tkselect userAnswers:_currentModel.userAnswer];
[_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{ -(void)nextBtnAction{
// if (_page == [_currentModel.totalCount integerValue] ) { [self saveProgress];
// GIGA_ShowToast(@"没有了");
// return; if (_page == self.questonArray.count ) {
// } GIGA_ShowToast(@"没有了");
// [self saveProgress]; [self submitAnswer];
// _page ++ ; return;
// // }
// [self getQuestionsInfo];
_page ++ ;
//
[self getQuestionsInfo];
//self.nextBtn.enabled = _page == [_currentModel.totalCount integerValue] ? NO : YES; //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 - #pragma mark -
-(void)saveProgress{ -(void)saveProgress{
// NSString *answer = self.questionView.selectAnswer;
// NSString *anserNum = self.questionView.qrnum; int questionId = _currentModel.questionId;
// NSString *anserid = _currentModel.questionid; QustionAnswer *curentAnswer = _currentModel.answerList[_curentAnswerIdex];
// GILog(@"选择答案:%@\n 角标:%@\n 题号:%@",answer,anserNum,anserid); 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 { - (void)didReceiveMemoryWarning {
@ -192,6 +358,4 @@
// Dispose of any resources that can be recreated. // Dispose of any resources that can be recreated.
} }
@end @end

View File

@ -7,31 +7,22 @@
// //
#import <JSONModel/JSONModel.h> #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 questionType;
//排序
@property (nonatomic,assign) int sortNum; @property (nonatomic,assign) int sortNum;
@property (nonatomic,copy) NSString *remark; @property (nonatomic,copy) NSString *remark;
@property (nonatomic,copy) NSString *question; @property (nonatomic,copy) NSString *question;
//optionsStyle:样式(单选或滑动) 1滑动2单选 3滑动带指示 4滑动渐变,
@property (nonatomic,assign) int optionsStyle;
@property (nonatomic,assign) int questionId;
@end @end

View File

@ -9,8 +9,14 @@
#import "ExercisesModel.h" #import "ExercisesModel.h"
@implementation ExercisesModel @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 @end

View File

@ -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

View File

@ -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

View File

@ -11,11 +11,11 @@ typedef NS_ENUM(NSInteger,GIGaQuestionSliderType)
{ {
GIGaQuestionSliderTypeGray = 0,//灰 GIGaQuestionSliderTypeGray = 0,//灰
GIGaQuestionSliderTypeGradient ,//变色 GIGaQuestionSliderTypeGradient ,//变色
GIGaQuestionSliderTypeIndicator //带指示器
}; };
@interface GIGaQuestionSlider : UISlider @interface GIGaQuestionSlider : UISlider
- (instancetype)initWithFrame:(CGRect)frame type:(GIGaQuestionSliderType)type; - (instancetype)initWithFrame:(CGRect)frame type:(GIGaQuestionSliderType)type;
@end @end

View File

@ -24,9 +24,10 @@
self.minimumValue = 0.0; self.minimumValue = 0.0;
self.maximumValue = 1.0; self.maximumValue = 1.0;
self.value = 0.5; self.value = 0.5;
[self creatSubView:type]; [self creatSubView:type];
} }
return self; return self;
} }
-(void)creatSubView:(GIGaQuestionSliderType)type{ -(void)creatSubView:(GIGaQuestionSliderType)type{
@ -37,12 +38,14 @@
{ {
[self createUI]; [self createUI];
} }
break; break;
case GIGaQuestionSliderTypeGradient: case GIGaQuestionSliderTypeGradient:
{ {
[self creatGradient]; [self creatGradient];
} }
break; break;
default: default:
break; break;
} }
@ -70,8 +73,6 @@
[self.layer addSublayer:gradientLayer]; [self.layer addSublayer:gradientLayer];
} }
-(void)createUI{ -(void)createUI{
self.minimumValue = 0.0; self.minimumValue = 0.0;
@ -82,6 +83,7 @@
} }
-(CGRect)trackRectForBounds:(CGRect)bounds -(CGRect)trackRectForBounds:(CGRect)bounds
{ {
bounds.origin.x = bounds.origin.x; bounds.origin.x = bounds.origin.x;

View File

@ -12,7 +12,7 @@
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <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"/> <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <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"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">

View File

@ -11,13 +11,23 @@
typedef NS_ENUM(NSInteger,MaskQuetionViewStyle) typedef NS_ENUM(NSInteger,MaskQuetionViewStyle)
{ {
MaskQuetionViewStleSliderNormal = 0,// 滑块正常 MaskQuetionViewStleSliderNormal = 0,// 滑块正常
MaskQuetionViewStleSliderGradient ,//滑块变色 MaskQuetionViewStleSliderGradient =1 ,//滑块变色
MaskQuetionViewStleYesOrNO // 是 否 MaskQuetionViewStleYesOrNO =2, // 是 否
MaskQuetionViewStyleSliderShowIndicator =3,//滑动带指示器
}; };
@protocol QeustionViewDelegate<NSObject>;
@optional
-(void)sliderChangeValueShouldChoiceModelAt:(NSInteger)index;
-(void)yesOrNoChoiceModelAt:(NSInteger)index;
@end
@interface MaskQuestionView : UIView @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; -(instancetype)initQuestionView:(CGRect)frame style:(MaskQuetionViewStyle)style titles:(NSArray *)titles;

View File

@ -9,11 +9,15 @@
#import "MaskQuestionView.h" #import "MaskQuestionView.h"
#import "GIGaQuestionSlider.h" #import "GIGaQuestionSlider.h"
#import "GiGaAnswerViewCell.h" #import "GiGaAnswerViewCell.h"
#import "NYSliderPopover.h"
#import "QustionAnswer.h"
@interface MaskQuestionView()<UITableViewDelegate,UITableViewDataSource> @interface MaskQuestionView()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) NSArray *dataArr; @property(nonatomic,strong) NSArray *dataArr;
@property(nonatomic,strong) UITableView *tableView; @property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) GIGaQuestionSlider *slider; @property(nonatomic,strong) GIGaQuestionSlider *slider;
@property(nonatomic,strong) NYSliderPopover *poSlider;
@end @end
@implementation MaskQuestionView @implementation MaskQuestionView
@ -29,11 +33,10 @@
-(instancetype)initQuestionView:(CGRect)frame style:(MaskQuetionViewStyle)style titles:(NSArray *)titles{ -(instancetype)initQuestionView:(CGRect)frame style:(MaskQuetionViewStyle)style titles:(NSArray *)titles{
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
self.dataArr = titles; self.dataArr = titles;
self.style = style;
[self creatSubs:style titles:titles]; [self creatSubs:style titles:titles];
} }
return self; return self;
} }
@ -43,19 +46,25 @@
case MaskQuetionViewStleSliderNormal: case MaskQuetionViewStleSliderNormal:
{ {
[self creatNormalStyle:titles]; [self creatNormalStyle:titles style:GIGaQuestionSliderTypeGray];
} }
break; break;
case MaskQuetionViewStleSliderGradient: case MaskQuetionViewStleSliderGradient:
{ {
[self creatNormalStyle:titles style:GIGaQuestionSliderTypeGradient];
} }
break; break;
case MaskQuetionViewStleYesOrNO: case MaskQuetionViewStleYesOrNO:
{ {
[self creatYseNoView];
}
break;
case MaskQuetionViewStyleSliderShowIndicator:
{
[self creatPopSlider];
} }
break; break;
default: default:
@ -64,10 +73,25 @@
} }
} }
-(void)creatNormalStyle:(NSArray *)titles{ -(void)creatPopSlider{
[self creatTab]; [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]; [slider addTarget:self action:@selector(updateValue:) forControlEvents:UIControlEventValueChanged];
self.slider = slider; self.slider = slider;
[self addSubview:slider]; [self addSubview:slider];
@ -77,14 +101,88 @@
-(void)layoutSubviews{ -(void)layoutSubviews{
[super 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{ -(void)updateValue:(UISlider *)slider{
NSLog(@"value%f",slider.value); 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{ -(void)creatTab{

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);//sizeCGSize
[image drawInRect:CGRectMake(0,0, size.width, size.height)];
UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@end