1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408 |
- /**
- */
- #import "ExerView.h"
- #import <AVKit/AVKit.h>
- #import "CommentCell.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- #import "RQYDTXCQuestionModule.h"
- @interface ExerView() <QMUIImagePreviewViewDelegate>
- //@interface ExerView()
- @property(nonatomic,strong)UILabel* lbl00;
- @property(nonatomic,strong)UILabel* lbl01;
- @property(nonatomic,strong)UIImageView* mediaImg;
- @property(nonatomic,strong)AVPlayerViewController *movie;
- @property(nonatomic,strong)AVPlayer *player;
- @property(nonatomic,strong)AVPlayerItem *playerItem;
- @property(nonatomic,strong)UIButton* playBtn;
- @property (nonatomic, readwrite, strong) MPPlayerController *mpPlayer;
- @property (nonatomic, readwrite, strong) ZFPlayerController *zfPlayer;
- @property (nonatomic, readwrite, strong) UIImageView *containerView;
- @property(nonatomic,strong)CLButton* btn02;
- @property(nonatomic,strong)CLButton* btn03;
- @property(nonatomic,strong)CLButton* btn04;
- @property(nonatomic,strong)CLButton* btn05;
- @property(nonatomic,strong)UIButton* btnYes;
- /**正确答案视图
- */
- @property(nonatomic,strong)UIView* answerV10;
- @property(nonatomic,strong)UILabel* lbl11;
- @property(nonatomic,strong)UILabel* lbl12;
- @property(nonatomic,strong)UIImageView* imgV13;
- @property(nonatomic,strong)NSMutableArray* imgs;
- @property(nonatomic,strong)UILabel* lbl14;
- /**评论的数据源
- */
- @property(nonatomic,strong)NSArray* comments;
- /**
- */
- /**其实下面的内容,可以由headerView,和tableView,footerView组合。
- 只需要设置tableview的frame即可。
-
- 反正子view是添加到父类里面的,无所谓。
- */
- @property (nonatomic, readwrite, strong) QMUIImagePreviewViewController *imagePreviewViewController;
- @end
- /**底部的试题分析的cell的个数最大值。
- */
- #define cellCntMax 3
- @implementation ExerView
- {
- NSMutableArray* optBtns;
-
- UIView *header;
- UIButton *footer ,*foldBtn;
- UITableView *myTableView;
-
- CGFloat tableH;
-
- // NSInteger answ;
- }
- /***控件需要一次性创建。
- 可是frame需要动态设置
- */
- -(id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- if (!self) {
- return nil;
- }
- [self setBackgroundColor:[UIColor whiteColor]];
- [self createSubViews];
- self.contentSize = SGSizeMake(0, 600);
- return self;
- }
- - (void)dealloc {
- if (self.zfPlayer) {
- [self.zfPlayer stop];
- self.zfPlayer = nil;
- }
- [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
- }
- /**每次设置question都需要动态设置frame
- */
- -(void)setSubViewFrame{
- @weakify(self)
- if (self.zfPlayer) {
- [self.zfPlayer stop];
- self.zfPlayer = nil;
- }
-
-
- CGFloat lbl01Y = 0;
-
- CGFloat lbl01X = 20;
- CGFloat lbl01W = kSize.width - lbl01X*2;
- CGFloat lbl01H = [_lbl01.text heightForWid:lbl01W Font:myDelegate.optionFont]+20;
- CGRect frame01 = CGRectMake(lbl01X, lbl01Y, lbl01W, lbl01H);
- self.lbl01.frame = frame01;
-
-
- CGFloat mediaH = 0;
- // CGRect frameMe ;//= CGRectZero;
- /**0:无图 1:图片题 2:动画题
- */
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if (RQStringIsEmpty(_ydtQuestionModel.media_url)) {
- /// 无图
- _mediaImg.hidden = YES;
- // _movie.view.hidden = YES;
- _containerView.hidden = YES;
- } else {
- if ([_ydtQuestionModel.media_url containsString:@".webp"]) {
- // _movie.view.hidden = YES;
- _containerView.hidden = YES;
- _mediaImg.hidden = NO;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- _mediaImg.frame = frameMe;
-
- NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.sinaimg)? _ydtQuestionModel.sinaimg : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
- NSData *imageData = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
- NSString *imageStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
- UIImage *subImage = [UIImage sd_imageWithData:[NSData dataWithBase64EncodedString:imageStr] scale:1 firstFrameOnly:YES];
-
- if (!RQObjectIsNil(subImage)) {
- if (RQ_COMMON_MANAGER.is_Online_Media_Image) {
- [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:subImage];
- } else {
- _mediaImg.image = subImage;
- }
- } else {
- [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:RQWebImagePlaceholder()];
- }
- mediaH = imgMH;
- } else if ([_ydtQuestionModel.media_url containsString:@".mp4"]) {
- // _movie.view.hidden = NO;
- _containerView.hidden = NO;
- _mediaImg.hidden = YES;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- self.containerView.frame = frameMe;
- @weakify(self)
- // self.mpPlayer = [[MPPlayerController alloc] initWithContainerView:self.containerView];
-
- NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.video_url)? _ydtQuestionModel.video_url : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
- NSData *data = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
- NSURL *moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
- if (!RQObjectIsNil(data)) {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *path = [documentsDirectory stringByAppendingPathComponent:media_name];
- [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
-
- moveUrl = [NSURL fileURLWithPath:path];
- if (RQ_COMMON_MANAGER.is_Online_Media_Video) {
- moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
- }
- }
- // self.containerView.image = [self videoImageWithvideoURL:moveUrl];
- self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.containerView];
- self.zfPlayer.currentPlayerManager.view.backgroundColor = UIColor.clearColor;
- self.zfPlayer.assetURLs = @[moveUrl];
- if (self.index == 1) {
- [self.zfPlayer playTheIndex:0];
- } else if ([self.questions.lastObject isEqual:_ydtQuestionModel] || [self.questions.firstObject isEqual:_ydtQuestionModel]) {
- [self.zfPlayer playTheIndex:0];
- }
- /// 播放完成
- self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) {
- @strongify(self)
- [self.zfPlayer.currentPlayerManager replay];
- };
- self.zfPlayer.playerPlayTimeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) {
- NSLog(@"%f---%f",currentTime,duration);
- };
- // self.mpPlayer.playableArray = @[_ydtQuestionModel];
- // [self.mpPlayer playWithPlayable:_ydtQuestionModel];
- // _movie.view.frame = frameMe;
- // NSURL *url = [NSURL URLWithString:_ydtQuestionModel.media_url];
- // _playerItem = [[AVPlayerItem alloc] initWithURL:url];
- // _player = [AVPlayer playerWithPlayerItem:_playerItem];
- // _movie.player = _player;
- // if (_movie.readyForDisplay) {
- // [_player play];
- // }
- // //添加播放完成通知
- // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
- mediaH = imgMH;
- } else {
-
- }
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- if (0 == _question.media_type.intValue) {
- _mediaImg.hidden = YES;
- _movie.view.hidden = YES;
- }
-
- if (1 == self.question.media_type.intValue)
- {
- _movie.view.hidden = YES;
- _mediaImg.hidden = NO;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- _mediaImg.frame = frameMe;
- if ([_question.media containsString:@".webp"]) {
- NSString *path = [[NSBundle mainBundle] pathForResource:[[_question.media componentsSeparatedByString:@"."] firstObject] ofType:@"webp"];
- _mediaImg.image = [UIImage sd_imageWithWebPData:[NSData dataWithContentsOfFile:path]];
- } else {
- _mediaImg.image = [UIImage imageNamed:_question.media];
- }
- mediaH = imgMH;
- }
-
- if (2 == _question.media_type.intValue) {
- _movie.view.hidden = NO;
- _mediaImg.hidden = YES;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- _movie.view.frame = frameMe;
- NSString *file=[[NSBundle mainBundle]pathForResource:_question.media ofType:nil];
- NSURL *url=[NSURL fileURLWithPath:file];
- _playerItem = [[AVPlayerItem alloc] initWithURL:url];
- _player = [AVPlayer playerWithPlayerItem:_playerItem];
- _movie.player = _player;
- if (_movie.readyForDisplay) {
- [_player play];
- }
- //添加播放完成通知
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
- mediaH = imgMH;
- }
- } else {
- if (RQStringIsEmpty(_ydtQuestionModel.media_url)) {
- /// 无图
- _mediaImg.hidden = YES;
- // _movie.view.hidden = YES;
- _containerView.hidden = YES;
- } else {
- if ([_ydtQuestionModel.media_url containsString:@".webp"]) {
- // _movie.view.hidden = YES;
- _containerView.hidden = YES;
- _mediaImg.hidden = NO;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- _mediaImg.frame = frameMe;
-
- NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.sinaimg)? _ydtQuestionModel.sinaimg : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
- NSData *imageData = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
- NSString *imageStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
- // NSData *subImageData = [[NSData alloc] initWithBase64EncodedString:imageStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
-
- UIImage *subImage = [UIImage sd_imageWithData:[NSData dataWithBase64EncodedString:imageStr] scale:1 firstFrameOnly:YES];
-
- if (!RQObjectIsNil(subImage)) {
- if (RQ_COMMON_MANAGER.is_Online_Media_Image) {
- [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:subImage];
- } else {
- _mediaImg.image = subImage;
- }
- } else {
- [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:RQWebImagePlaceholder()];
- }
- mediaH = imgMH;
- } else if ([_ydtQuestionModel.media_url containsString:@".mp4"]) {
- // _movie.view.hidden = NO;
- _containerView.hidden = NO;
- _mediaImg.hidden = YES;
- CGFloat imgMX = 10;
- CGFloat imgMY = CGRectGetMaxY(frame01);
- CGFloat imgMW = kSize.width - 20;
- CGFloat imgMH = imgMW *0.5;
- CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
- self.containerView.frame = frameMe;
- @weakify(self)
- // self.mpPlayer = [[MPPlayerController alloc] initWithContainerView:self.containerView];
-
- NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.video_url)? _ydtQuestionModel.video_url : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
- NSData *data = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
- NSURL *moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
- if (!RQObjectIsNil(data)) {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *path = [documentsDirectory stringByAppendingPathComponent:media_name];
- [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
-
- moveUrl = [NSURL fileURLWithPath:path];
- if (RQ_COMMON_MANAGER.is_Online_Media_Video) {
- moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
- }
- }
- // self.containerView.image = [self videoImageWithvideoURL:moveUrl];
- self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.containerView];
- self.zfPlayer.currentPlayerManager.view.backgroundColor = UIColor.clearColor;
- self.zfPlayer.assetURLs = @[moveUrl];
- if (self.index == 1) {
- [self.zfPlayer playTheIndex:0];
- } else if ([self.questions.lastObject isEqual:_ydtQuestionModel] || [self.questions.firstObject isEqual:_ydtQuestionModel]) {
- [self.zfPlayer playTheIndex:0];
- }
- /// 播放完成
- self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) {
- @strongify(self)
- [self.zfPlayer.currentPlayerManager replay];
- };
- self.zfPlayer.playerPlayTimeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) {
- NSLog(@"%f---%f",currentTime,duration);
- };
- // self.mpPlayer.playableArray = @[_ydtQuestionModel];
- // [self.mpPlayer playWithPlayable:_ydtQuestionModel];
- // _movie.view.frame = frameMe;
- // NSURL *url = [NSURL URLWithString:_ydtQuestionModel.media_url];
- // _playerItem = [[AVPlayerItem alloc] initWithURL:url];
- // _player = [AVPlayer playerWithPlayerItem:_playerItem];
- // _movie.player = _player;
- // if (_movie.readyForDisplay) {
- // [_player play];
- // }
- // //添加播放完成通知
- // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
- mediaH = imgMH;
- } else {
-
- }
- }
- }
- }
-
-
-
-
- /**A
- */
- CGFloat btn02X =0;
- CGFloat btn02Y =CGRectGetMaxY(frame01) + mediaH +kCellBd ;
- CGFloat btn02W =kSize.width;
- CGFloat btn02H =40.0;
- CGRect frame02 = CGRectMake(btn02X, btn02Y, btn02W, btn02H);
- self.btn02.frame = frame02;
- // CLButton* btn;
-
- /**B
- */
- CGFloat btn03X =0;
- CGFloat btn03Y =CGRectGetMaxY(frame02)+kCellBd;
- CGFloat btn03W =kSize.width;
- CGFloat btn03H =40.0;
- CGRect frame03 = CGRectMake(btn03X, btn03Y, btn03W, btn03H);
- self.btn03.frame = frame03;
-
- /**C
- */
- CGFloat btn04X =0;
- CGFloat btn04Y =CGRectGetMaxY(frame03)+kCellBd;
- CGFloat btn04W =kSize.width;
- CGFloat btn04H =40.0;
- CGRect frame04 = CGRectMake(btn04X, btn04Y, btn04W, btn04H);
- self.btn04.frame = frame04;
-
- /**D
- */
- CGFloat btn05X =0;
- CGFloat btn05Y =CGRectGetMaxY(frame04)+kCellBd;
- CGFloat btn05W =kSize.width;
- CGFloat btn05H =40.0;
- CGRect frame05 = CGRectMake(btn05X, btn05Y, btn05W, btn05H);
- self.btn05.frame = frame05;
-
- CGFloat x,y,h,w;
- x = 80;
- w = kSize.width - x*2;
- y = btn05Y + btn05H + 30;
- h = 55;
- _btnYes.frame = CGRectMake(x, y, w, h);
-
- CGFloat ansVX = 0;
- CGFloat ansVY = 0;
- /**如果是判断题
- */
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if (_ydtQuestionModel.Type == 1) {
- ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
- } else {
- ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- if (0 == _question.option_type.intValue) {
- ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
- }else{
- ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
- }
- } else {
- if (_ydtQuestionModel.Type == 1) {
- ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
- } else {
- ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
- }
- }
- }
-
-
-
- CGFloat ansVW = kSize.width;
- CGFloat ansVH = 500;
- CGRect frameAnV = CGRectMake(ansVX, ansVY, ansVW, ansVH);
- self.answerV10.frame = frameAnV;
-
- CGFloat lbl11X = 10;
- CGFloat lbl11Y = kSecHeadHeight;
- CGFloat lbl11W = 150;
- CGFloat lbl11H = 30;
- CGRect frame11 = CGRectMake(lbl11X, lbl11Y, lbl11W, lbl11H);
- self.lbl11.text = @"最佳解释";
- self.lbl11.frame = frame11;
- self.lbl11.textColor = defGreen;
- // UILabel* label;
-
- CGFloat img13H = 20;
- CGFloat img13W = img13H*5;
- CGFloat img13Y = kSecHeadHeight;
- CGFloat img13X = kSize.width - img13W - 10;
- CGRect frame13 = CGRectMake(img13X, img13Y, img13W, img13H);
- self.imgV13.frame = frame13;
-
- // int i=0;
- // for (UIImageView* iv in _imgs)
- // {
- // iv.frame = CGRectMake(img13X + img13W/5*i, img13Y+5, img13H -3, img13H-3);
- // iv.image = [UIImage imageNamed:@"rankstar0_img.png"];
- // i++;
- // }
-
- // CGFloat lbl12W = 60;
- // CGFloat lbl12H = 30;
- // CGFloat lbl12X = CGRectGetMinX(frame13) - lbl12W;
- // CGFloat lbl12Y = kSecHeadHeight;
- // CGRect frame12 = CGRectMake(lbl12X, lbl12Y, lbl12W, lbl12H);
- self.lbl12.text = @"难度";
- // self.lbl12.frame = frame12;
-
- /**解释
- */
- CGFloat lbl14X = 10;
- CGFloat lbl14Y = CGRectGetMaxY(frame11) + kSecHeadHeight;
- CGFloat lbl14W = kSize.width - lbl14X*2;
- CGFloat lbl14H = [_lbl14.text heightForWid:lbl14W Font:myDelegate.optionFont]+20;
- CGRect frame14 = CGRectMake(lbl14X, lbl14Y, lbl14W, lbl14H);
- self.lbl14.frame = frame14;
-
- CGFloat currentTop = lbl14Y + lbl14H;
- [header setFrame:CGRectMake(0, currentTop + 10, kSize.width, 30)];
-
- currentTop +=55;
- [myTableView setFrame:CGRectMake(0, currentTop , kSize.width, tableH)];
- [footer setFrame:CGRectMake(0, currentTop + tableH, kSize.width, 40)];
- [myTableView setBackgroundColor:[UIColor clearColor]];
-
- _answerV10.height = footer.bottom;
-
-
- if (_answerV10.hidden) {
- [self setContentSize:kSize];
- }else{
- [self setContentSize:CGSizeMake(0,_answerV10.bottom+100)];
- }
- }
- -(void)createSubViews
- {
- _comments = [NSArray array];
-
- UILabel* lbl01 = [[UILabel alloc] init];
- lbl01.font = [UIFont scaleSize:myDelegate.optionFont];
- lbl01.textColor = [UIColor grayColor];
- lbl01.numberOfLines = 0;
- [self addSubview:lbl01];
-
- self.lbl01 = lbl01;
-
- UILabel* lbl00 = [[UILabel alloc] init];
- self.lbl00 = lbl00;
-
- _mediaImg = [[UIImageView alloc] init];
- [_mediaImg setContentMode:UIViewContentModeScaleAspectFit];
- [_mediaImg setClipsToBounds:YES];
- [_mediaImg setBackgroundColor:[UIColor clearColor]];
- [self addSubview:_mediaImg];
- //图片题放大
- [_mediaImg setUserInteractionEnabled:YES];
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(magnifyImage)];
- //把手势添加到指定视图上
- [_mediaImg addGestureRecognizer:tapGesture];
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [self addSubview:self.containerView];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- _movie = [[AVPlayerViewController alloc] init];
- _movie.showsPlaybackControls = NO;
- [self addSubview:_movie.view];
- } else {
- [self addSubview:self.containerView];
- }
- }
-
-
-
-
- optBtns = [NSMutableArray array];
- /**A
- */
- CLButton* btn02= [[CLButton alloc] init];
- btn02.imgN = @"option_A.png";
- [optBtns addObject:btn02];
- self.btn02 = btn02;
- btn02.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 1 *10000 : ([defUser.car_type isEqualToString:@"2"]? 16 : 1 *10000);
- [self addSubview:btn02];
- [btn02 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
- CLButton* btn;
- btn = self.btn02;
- [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
-
- /**B
- */
-
- CLButton* btn03= [[CLButton alloc] init];
- self.btn03 = btn03;
- btn03.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 2 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 32 : 2 * 10000);
- btn03.imgN = @"option_B.png";
- [self addSubview:btn03];
- [btn03 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
- [optBtns addObject:btn03]; btn = self.btn03;
- [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
-
- /**C
- */
-
- CLButton* btn04= [[CLButton alloc] init];
- [btn04 setImage:defaultImg forState:UIControlStateNormal];
- self.btn04 = btn04;
- btn04.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 3 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 64 : 3 * 10000);
- btn04.imgN = @"option_C.png";
- [self addSubview:btn04];
- [btn04 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
- [optBtns addObject:btn04];
- btn = self.btn04;
- [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
- /**D
- */
-
- CLButton* btn05= [[CLButton alloc] init];
- self.btn05 = btn05;
- btn05.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 4 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 128 : 4 * 10000);
- btn05.imgN = @"option_D.png";
- [self addSubview:btn05];
- [btn05 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
- [optBtns addObject:btn05];
- btn = self.btn05;
- [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
-
- _btnYes = [[UIButton alloc] init];
- [_btnYes setBackgroundColor:KlineColor];
- [_btnYes setTitle:@"确定" textColor:subTitleColor font:22 fotState:UIControlStateNormal];
- [_btnYes addTarget:self action:@selector(multiOptsYes:) forControlEvents:UIControlEventTouchUpInside];
- _btnYes.layer.cornerRadius = 10;
- [self addSubview:_btnYes];
-
- UIView* view10 = [[UIView alloc] init];
- self.answerV10 = view10;
- [self addSubview:view10];
-
- self.lbl11 = [[UILabel alloc] init];
- [self.answerV10 addSubview:self.lbl11];
- UILabel* label = self.lbl11;
- [label addSelfViewWithRect:CGRectMake(-10, -12, kSize.width, 8) Color:KlineColor];
-
- self.lbl12 = [[UILabel alloc] init];
- [self.answerV10 addSubview:self.lbl12];
- self.imgV13 = [[UIImageView alloc] init];
- [self.answerV10 addSubview:self.imgV13];
- //解释。label
- self.lbl14 = [[UILabel alloc] init];
- [self.answerV10 addSubview:self.lbl14];
- label = self.lbl14;
- [label setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [label addSelfViewWithRect:CGRectMake(-10, -10, kSize.width, .5) Color:KlineColor];
-
- _imgs = [NSMutableArray array];
- for (int i=0; i<5; i++) {
- UIImageView *iv = [[UIImageView alloc] init];
- [_imgs addObject:iv];
- [self.answerV10 addSubview:iv];
- }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- myTableView = [[UITableView alloc] init];
- [myTableView setDataSource:self];
- [myTableView setDelegate:self];
- myTableView.separatorInset = UIEdgeInsetsMake(0,70, 0, 10);
- [self.answerV10 addSubview:myTableView];
- tableH = 0;
-
- //header
- UIView* vi = [[UIView alloc] initWithFrame:SGRectMake(0, 0, 320, 25)];
- [_answerV10 addSubview:vi];
- label = [[UILabel alloc] initWithFrame:SGRectMake(10, 0, 80, 25)];
- [label setText:@"试题分析"];
- [label setTextColor:contentTextColor];
-
- [vi addSubview:label];
- header = vi;
- [label addSelfViewWithRect:SGRectMake(-10, -10, 320, 7) Color:KlineColor];
- [label addSelfViewWithRect:SGRectMake(-10, 26, 320, .5) Color:KlineColor];
-
- /**普通状态显示展开。选定状态显示收起
- */
- UIButton* btnn;
- btnn = [[UIButton alloc] initWithFrame:SGRectMake(90, 0, 80, 25)];
- [btnn setTitle:@"展开" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- [btnn setTitle:@"收起" textColor:defGreen font:NormalFont fotState:UIControlStateSelected];
- [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
- [vi addSubview:btnn];
- [btnn setTag:0];
- foldBtn = btnn;
-
- btnn = [[UIButton alloc] initWithFrame:SGRectMake(320-90, 2.5, 80, 20)];
- [btnn setTitle:@"我来分析" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
- [btnn setBoardWid:.5 Color:defGreen];
- [vi addSubview:btnn];
- [btnn setTag:1];
-
- btnn = [[UIButton alloc] init];
-
- [btnn setTitle:@"查看全部学员分析" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
- [_answerV10 addSubview:btnn];
- footer = btnn;
- [btnn addSelfViewWithRect:SGRectMake(0, 40, 320, .5) Color:KlineColor];
- [btnn setTag:2];
-
-
- [myTableView setHidden:YES];
- [footer setHidden:YES];
- }
-
-
- }
- #pragma mark - 接收播放完成的通知
- - (void)runLoopTheMovie:(NSNotification *)notification {
- AVPlayerItem *playerItem = notification.object;
- [playerItem seekToTime:kCMTimeZero];
- [_player play];
- }
- //图片放大
- - (void)magnifyImage {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [RQControllerHelper.currentViewController presentViewController:self.imagePreviewViewController animated:YES completion:nil];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:@[_mediaImg.image] currentIndex:0 isCanSave:NO];
- } else {
- [RQControllerHelper.currentViewController presentViewController:self.imagePreviewViewController animated:YES completion:nil];
- }
- }
- }
- - (void)setQuestion:(Question *)question {
- if(!question){
- return;
- }
- self.comments = nil;
- [myTableView reloadData];
- [foldBtn setSelected:NO];
- [myTableView setHidden:YES];
- [footer setHidden:YES];
- _btnYes.enabled = NO;
-
- [self setContentOffset:CGPointMake(0, 0)];
- _playBtn.hidden = YES;
- self.answerV10.hidden = YES;
- _question = question;
- for (UIButton* btn in optBtns) {
- [btn setSelected:NO];
- [btn setBackgroundColor:[UIColor clearColor]];
- }
-
- switch (question.option_type.intValue) {
- case 0:
- self.lbl00.text = @"判断";
- self.btn04.hidden = YES;
- self.btn05.hidden = YES;
- _btnYes.hidden = YES;
- break;
- case 1:
- self.lbl00.text = @"单选";
- self.btn04.hidden = NO;
- self.btn05.hidden = NO;
- _btnYes.hidden = YES;
- break;
- case 2:
- self.lbl00.text = @"多选";
- self.btn04.hidden = NO;
- self.btn05.hidden = NO;
- _btnYes.hidden = NO;
- break;
-
- default:
- break;
- }
- self.lbl01.text = [NSString stringWithFormat:@" %@:%@",self.lbl00.text,question.question];
-
- [self.btn02 setTitle:question.optionA forState:UIControlStateNormal];
- [self.btn03 setTitle:question.optionB forState:UIControlStateNormal];
- [self.btn04 setTitle:question.optionC forState:UIControlStateNormal];
- [self.btn05 setTitle:question.optionD forState:UIControlStateNormal];
-
-
-
- self.btn02.hidden = !question.optionA || [question.optionA isEqualToString:@""];
- self.btn03.hidden = !question.optionB || [question.optionB isEqualToString:@""];
- self.btn04.hidden = !question.optionC || [question.optionC isEqualToString:@""];
- self.btn05.hidden = !question.optionD || [question.optionD isEqualToString:@""];
-
- /**
- 选项字体 一键设置
- */
- [self.lbl01 setFont:[UIFont scaleSize:myDelegate.optionFont]];
-
- [self.btn02.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn03.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn04.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn05.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
-
- _btn02.imgN = @"option_A.png";
- _btn03.imgN = @"option_B.png";
- _btn04.imgN = @"option_C.png";
- _btn05.imgN = @"option_D.png";
- for (CLButton* btn in optBtns)
- {
- [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- }
-
- [self.lbl14 setFont:[UIFont scaleSize:myDelegate.optionFont]];
- self.lbl14.numberOfLines = 0;
- self.lbl14.text = _question.explain;
-
- [self setSubViewFrame];
- }
- - (void)setYdtQuestionModel:(RQYDTQuestionModel *)ydtQuestionModel
- {
- if(!ydtQuestionModel){
- return;
- }
- self.comments = nil;
- [myTableView reloadData];
- [foldBtn setSelected:NO];
- [myTableView setHidden:YES];
- [footer setHidden:YES];
- _btnYes.enabled = NO;
-
- [self setContentOffset:CGPointMake(0, 0)];
- _playBtn.hidden = YES;
- self.answerV10.hidden = YES;
- _ydtQuestionModel = ydtQuestionModel;
- for (UIButton* btn in optBtns) {
- [btn setSelected:NO];
- [btn setBackgroundColor:[UIColor clearColor]];
- }
-
- switch (_ydtQuestionModel.Type) {
- case 1:
- self.lbl00.text = @"判断";
- self.btn04.hidden = YES;
- self.btn05.hidden = YES;
- _btnYes.hidden = YES;
- break;
- case 2:
- self.lbl00.text = @"单选";
- self.btn04.hidden = NO;
- self.btn05.hidden = NO;
- _btnYes.hidden = YES;
- break;
- case 3:
- self.lbl00.text = @"多选";
- self.btn04.hidden = NO;
- self.btn05.hidden = NO;
- _btnYes.hidden = NO;
- break;
-
- default:
- break;
- }
-
- self.lbl01.text = [NSString stringWithFormat:@" %@:%@",self.lbl00.text,_ydtQuestionModel.Question];
- [self.btn02 setTitle:(_ydtQuestionModel.Type == 1)? @"正确" : _ydtQuestionModel.An1 forState:UIControlStateNormal];
- [self.btn03 setTitle:(_ydtQuestionModel.Type == 1)? @"错误" : _ydtQuestionModel.An2 forState:UIControlStateNormal];
- [self.btn04 setTitle:_ydtQuestionModel.An3 forState:UIControlStateNormal];
- [self.btn05 setTitle:_ydtQuestionModel.An4 forState:UIControlStateNormal];
-
- // self.btn02.hidden = !ydtQuestionModel.An1 || [ydtQuestionModel.An1 isEqualToString:@""];
- // self.btn03.hidden = !ydtQuestionModel.An2 || [ydtQuestionModel.An2 isEqualToString:@""];
- self.btn04.hidden = !ydtQuestionModel.An3 || [ydtQuestionModel.An3 isEqualToString:@""];
- self.btn05.hidden = !ydtQuestionModel.An4 || [ydtQuestionModel.An4 isEqualToString:@""];
-
- /**
- 选项字体 一键设置
- */
- [self.lbl01 setFont:[UIFont scaleSize:myDelegate.optionFont]];
-
- [self.btn02.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn03.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn04.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
- [self.btn05.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
-
- _btn02.imgN = @"option_A.png";
- _btn03.imgN = @"option_B.png";
- _btn04.imgN = @"option_C.png";
- _btn05.imgN = @"option_D.png";
- for (CLButton* btn in optBtns)
- {
- [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- }
-
- [self.lbl14 setFont:[UIFont scaleSize:myDelegate.optionFont]];
- self.lbl14.numberOfLines = 0;
- self.lbl14.text = _ydtQuestionModel.explain;
-
- [self setSubViewFrame];
- }
- //改变背景颜色 实现夜间模式
- -(void)setNightMode:(BOOL)isNight
- {
- if (isNight)
- {
- [self setBackgroundColor:nightColor];//[UIColor orangeColor]
- }
- else
- {
- [self setBackgroundColor:[UIColor whiteColor]];
- }
- }
- #pragma mark -
- -(void)getAllComments
- {
- @weakify(self)
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr property:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? @(_ydtQuestionModel.ID) : ([defUser.car_type isEqualToString:@"2"]? _question._id : @(_ydtQuestionModel.ID)) forKey:@"id"];
- [arr property:@"1" forKey:@"isPage"];
- [arr property:@"7" forKey:@"pageSize"];
- [arr property:@"1" forKey:@"currentPage"];
-
- NSString* method = @"getQuestionComments";
- [MBProgressHUD showLoadToView:self];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
- @strongify(self)
- [MBProgressHUD hideHUDForView:self];
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ([dict[@"code"] isEqualToString:@"1"])
- {
- ShowMsg(dict[@"body"]);
- return;
- }
-
- _comments = dict[@"body"];
- if (![dict[@"body"] isKindOfClass:[NSArray class]]) {
- _comments = @[];
- }
-
- if (_comments.count < 1) {
- ShowMsg(@"暂无相关评论");
- }
-
- /*题目分析 剩下两个找不到(你晚上看看)
- PHOTO = "";
- "QC_CRDATE" = "2017-01-23 16:08:44";
- "QC_DESC" = gdfgfd;
- "QC_DOWN_NUM" = 0;
- "QC_ID" = 61;
- "QC_QID" = 1;
- "QC_TYPE" = 1;
- "QC_UP_NUM" = 0;
- "QC_USER_ID" = 1;
- */
-
- tableH = 0;
- for (int i=0; i< _comments.count && i < cellCntMax; i++) {
-
- NSDictionary *dic = _comments[i];
- tableH += 105 + [dic[@"QC_DESC"] heightForWid:(kSize.width - 80) Font:15];
- }
-
- // [footer setTitle:[NSString stringWithFormat:@"查看全部%d位学员分析",(int)_comments.count] textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- [myTableView reloadData];
- [self setSubViewFrame];
- }];
- }
- -(void)showComments:(BOOL)isShow
- {
- if (isShow) {
- }else{
- }
- }
- -(void)btnHereClick:(UIButton*)sender{
-
- if (0 == sender.tag)
- {
- [myTableView setHidden:sender.selected];
- [footer setHidden:sender.selected];
- sender.selected = !sender.selected;
-
- if (sender.selected) {
- [self getAllComments];
- }
- }else{
- [self.delegate2 gotoAllCommentVC];
- }
- }
- -(void)setShowAnswer:(BOOL)showAnswer
- {
- [_answerV10 setHidden:!showAnswer];
- }
- -(void)playMovie
- {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if (RQStringIsNotEmpty(_ydtQuestionModel.video_url)) {
- [self.mpPlayer playWithPlayable:_ydtQuestionModel];
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- if (_question.media_type.intValue == 2)
- {
- [_player play];
- }
- } else {
- if (RQStringIsNotEmpty(_ydtQuestionModel.video_url)) {
- [self.mpPlayer playWithPlayable:_ydtQuestionModel];
- }
- }
- }
- }
- -(void)stopMovie
- {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [_player pause];
- }
- }
-
-
- if (self.zfPlayer) {
- [self.zfPlayer stop];
- self.zfPlayer = nil;
- }
- }
- /**4个按钮用tag来区分。16,32,64,128
- 当点击按钮后,设置正确答案的img
- 如果答题错误,把点的按钮变成错误的img
- 不管是否正确都要跳出正确答案,
- */
- -(void)AAction:(CLButton*)sender
- {
-
- int type = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? _ydtQuestionModel.Type : ([defUser.car_type isEqualToString:@"2"]? _question.option_type.intValue : _ydtQuestionModel.Type);
- if (type == (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 3 : ([defUser.car_type isEqualToString:@"2"]? 2 : 3))) {
- sender.selected = !sender.selected;
- if (sender.selected) {
- [sender setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];//backGroundColor
- }else{
- [sender setBackgroundColor:[UIColor clearColor]];
- }
-
- int optCnt = 0;
- for (int i=0; i<4; i++)
- {
- UIButton* btn = optBtns[i];
- if (btn.selected) {
- optCnt++;
- }
- }
- if (optCnt > 1) {
- _btnYes.enabled = YES;
- [_btnYes setBackgroundColor:defGreen];
- }else{
- _btnYes.enabled = NO;
- [_btnYes setBackgroundColor:KlineColor];
- }
- return;
- }
-
- if ([self.delegate2 respondsToSelector:@selector(didChooseOption:isRight:)]) {
- [self.delegate2 didChooseOption:sender.tag isRight:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (_ydtQuestionModel.AnswerTrue.intValue == (sender.tag / 10000)) : ([defUser.car_type isEqualToString:@"2"]? (_question.answer.intValue == sender.tag) : (_ydtQuestionModel.AnswerTrue.intValue == (sender.tag / 10000)))];
- }
- [self choose:sender.tag];
- return;
- }
- /**展示答案的权利,交给exVC。这里就不去设置了。
- 这里主要是根据。opt设置按钮的图片。
- */
- -(void)choose:(NSInteger)opt
- {
- _btn02.enabled = NO;
- _btn03.enabled = NO;
- _btn04.enabled = NO;
- _btn05.enabled = NO;
- _btnYes.hidden = YES;
-
- int type = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? _ydtQuestionModel.Type : ([defUser.car_type isEqualToString:@"2"]? _question.option_type.intValue : _ydtQuestionModel.Type);
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if ( 3 == type) {
- NSString* answer = _ydtQuestionModel.AnswerTrue;
- NSString* myAnswer = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:opt]];
- NSArray* arr = @[@"1",@"2",@"3",@"4"];
- for (int i = 0; i < 4; i++) {
- CLButton* btn = optBtns[i];
- NSRange range = [answer rangeOfString:arr[i]];
- NSRange myRange = [myAnswer rangeOfString:arr[i]];
- BOOL isSel = (myRange.location != NSNotFound);
- BOOL isRig = (range.location != NSNotFound);
- if (isSel) {
- [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];
- }else{
- [btn setBackgroundColor:[UIColor clearColor]];
- }
- if (isRig) {
- btn.imgN = @"question_correct.png";
- }else if (isSel){
- btn.imgN = @"question_error.png";
- }
- }
-
- return;
- }
- for (CLButton* btn in optBtns) {
- if (_ydtQuestionModel.AnswerTrue.intValue == (btn.tag / 10000))
- {
- btn.imgN = @"question_correct.png";
- [btn setTitleColor:defGreen forState:UIControlStateNormal];
- }
- }
- if ((opt / 10000) != _ydtQuestionModel.AnswerTrue.intValue) {
- switch (opt / 10000) {
- case 1:
- _btn02.imgN = @"question_error.png";
- break;
- case 2:
- _btn03.imgN = @"question_error.png";
- break;
- case 3:
- _btn04.imgN = @"question_error.png";
- break;
- case 4:
- _btn05.imgN = @"question_error.png";
- break;
- default:
- break;
- }
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- if ( 2 == type) {
- NSString* answer = [Util getAnswerByTen:_question.answer.intValue];
- NSString* myAnswer = [Util getAnswerByTen:opt];
- NSArray* arr = @[@"A",@"B",@"C",@"D"];
- for (int i = 0; i < 4; i++) {
- CLButton* btn = optBtns[i];
- NSRange range = [answer rangeOfString:arr[i]];
- NSRange myRange = [myAnswer rangeOfString:arr[i]];
- BOOL isSel = (myRange.location != NSNotFound);
- BOOL isRig = (range.location != NSNotFound);
- if (isSel) {
- [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];//klinecolor
- }else{
- [btn setBackgroundColor:[UIColor clearColor]];
- }
- if (isRig) {
- btn.imgN = @"question_correct.png";
- }else if (isSel){
- btn.imgN = @"question_error.png";
- }
- }
-
- return;
- }
- for (CLButton* btn in optBtns) {
- if (_question.answer.intValue == btn.tag)
- {
- btn.imgN = @"question_correct.png";
- [btn setTitleColor:defGreen forState:UIControlStateNormal];
- }
- }
- if (opt != _question.answer.intValue) {
- switch (opt) {
- case 16:
- _btn02.imgN = @"question_error.png";
-
- break;
- case 32:
- _btn03.imgN = @"question_error.png";
- break;
- case 64:
- _btn04.imgN = @"question_error.png";
- break;
- case 128:
- _btn05.imgN = @"question_error.png";
- break;
- default:
- break;
- }
- }
- } else {
- if ( 3 == type) {
- NSString* answer = _ydtQuestionModel.AnswerTrue;
- NSString* myAnswer = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:opt]];
- NSArray* arr = @[@"1",@"2",@"3",@"4"];
- for (int i = 0; i < 4; i++) {
- CLButton* btn = optBtns[i];
- NSRange range = [answer rangeOfString:arr[i]];
- NSRange myRange = [myAnswer rangeOfString:arr[i]];
- BOOL isSel = (myRange.location != NSNotFound);
- BOOL isRig = (range.location != NSNotFound);
- if (isSel) {
- [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];
- }else{
- [btn setBackgroundColor:[UIColor clearColor]];
- }
- if (isRig) {
- btn.imgN = @"question_correct.png";
- }else if (isSel){
- btn.imgN = @"question_error.png";
- }
- }
-
- return;
- }
- for (CLButton* btn in optBtns) {
- if (_ydtQuestionModel.AnswerTrue.intValue == (btn.tag / 10000))
- {
- btn.imgN = @"question_correct.png";
- [btn setTitleColor:defGreen forState:UIControlStateNormal];
- }
- }
- if ((opt / 10000) != _ydtQuestionModel.AnswerTrue.intValue) {
- switch (opt / 10000) {
- case 1:
- _btn02.imgN = @"question_error.png";
- break;
- case 2:
- _btn03.imgN = @"question_error.png";
- break;
- case 3:
- _btn04.imgN = @"question_error.png";
- break;
- case 4:
- _btn05.imgN = @"question_error.png";
- break;
- default:
- break;
- }
- }
- }
- }
-
-
-
-
-
- }
- -(void)multiOptsYes:(UIButton*)sender
- {
- NSInteger answ = 0;
- NSArray* arr = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? @[@"1",@"2",@"3",@"4"] : ([defUser.car_type isEqualToString:@"2"]? @[@"16",@"32",@"64",@"128"] : @[@"1",@"2",@"3",@"4"]);
- NSMutableString *str = [NSMutableString string];
- for (int i=0; i<4; i++)
- {
- UIButton* btn = optBtns[i];
- if (btn.selected) {
- [str appendString:arr[i]];
- answ += [arr[i] integerValue];
- }
- }
-
- if ([self.delegate2 respondsToSelector:@selector(didChooseOption:isRight:)]) {
- [self.delegate2 didChooseOption:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? str.integerValue : ([defUser.car_type isEqualToString:@"2"]? answ : str.integerValue) isRight:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? (_ydtQuestionModel.AnswerTrue.intValue == str.integerValue) : ([defUser.car_type isEqualToString:@"2"]? (_question.answer.intValue == answ) : (_ydtQuestionModel.AnswerTrue.intValue == str.integerValue))];
- }
- [self choose:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? str.integerValue : ([defUser.car_type isEqualToString:@"2"]? answ : str.integerValue)];
- }
- /**
- 使用方法:首先是setQuestion。然后是setAnswer
- 0要恢复按钮点击。
- 16-128要调用choose,表示做过了。
-
- 这里也要判断一下。是单选还是多选。
- */
- -(void)setAnswer:(NSInteger)answer
- {
- if (0 == answer)
- {
- _btn02.enabled = YES;
- _btn03.enabled = YES;
- _btn04.enabled = YES;
- _btn05.enabled = YES;
-
- _btnYes.enabled = NO;
- [_btnYes setBackgroundColor:KlineColor];
-
- return;
- }
- [self choose:answer];
-
- return;
- }
- #pragma mark -
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _comments.count > cellCntMax ? cellCntMax : _comments.count;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSDictionary *dic = _comments[indexPath.row];
- return 110 + [dic[@"QC_DESC"] heightForWid:(kSize.width - 80) Font:15];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CommentCell* cell = [CommentCell cellForTableView:tableView Style:CommentCellStyleQuestion];
- [cell setCommentDic:_comments[indexPath.row]];
- return cell;
- }
- - (UIImage*)videoImageWithvideoURL:(NSURL *)videoURL {
- NSString *cacheKeyStr = [[YYWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:videoURL.absoluteString]];
- UIImage *memoryImage = [[YYImageCache sharedCache] getImageForKey:cacheKeyStr];
- if (memoryImage) {
- return memoryImage;
- } else {
- UIImage *thumbnailImage = [self firstFrameWithVideoURL:videoURL size:CGSizeMake(RQ_SCREEN_WIDTH - 32.f, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT)];
- dispatch_async(dispatch_get_main_queue(), ^{
- YYImageCache * cache = [YYImageCache sharedCache];
- [cache setImage:thumbnailImage forKey:videoURL.absoluteString];
- });
- return thumbnailImage;
- }
- }
- // 获取视频第一帧
- - (UIImage*)firstFrameWithVideoURL:(NSURL*)url size:(CGSize)size {
- NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
- AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
- AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
- generator.appliesPreferredTrackTransform = YES;
- generator.maximumSize = CGSizeMake(size.width, size.height);
- NSError*error =nil;
- CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(0, 10) actualTime:NULL error:&error];
- {
- return [UIImage imageWithCGImage:img];
- }
- return nil;
- }
- #pragma mark - <QMUIImagePreviewViewDelegate>
- - (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
- return 1;
- }
- - (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
- zoomImageView.reusedIdentifier = @(index);
-
- // 模拟异步加载的情况
- if (index == 2) {
- [zoomImageView showLoading];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if ([zoomImageView.reusedIdentifier isEqual:@(index)]) {
- [zoomImageView hideEmptyView];
- zoomImageView.image = _mediaImg.image;
- zoomImageView.contentMode = UIViewContentModeScaleAspectFill;
- zoomImageView.maximumZoomScale = 3.f;
- }
- });
- } else {
- zoomImageView.image = _mediaImg.image;
- }
- }
- - (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
- return QMUIImagePreviewMediaTypeImage;
- }
- #pragma mark - <QMUIZoomImageViewDelegate>
- - (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
- // 退出图片预览
- [RQControllerHelper.currentViewController dismissViewControllerAnimated:YES completion:^{
-
- }];
- }
- #pragma mark - LazyLoad
- - (UIImageView *)containerView {
- if (!_containerView) {
- _containerView = [[UIImageView alloc] qmui_initWithSize:CGSizeMake(RQ_SCREEN_WIDTH - 20, (RQ_SCREEN_WIDTH - 20) / 2.f)];
- _containerView.backgroundColor = UIColor.blackColor;
- UILabel *loadingLabel = [[UILabel alloc] qmui_initWithFont:RQRegularFont(25) textColor:RQ_MAIN_TEXT_COLOR_WHITE];
- loadingLabel.text = @"画面加载中...";
- [_containerView addSubview:loadingLabel];
- [loadingLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(_containerView);
- }];
- }
- return _containerView;
- }
- - (void)setIndex:(NSInteger)index {
- _index = index;
- }
- - (QMUIImagePreviewViewController *)imagePreviewViewController {
- @weakify(self)
- if (!_imagePreviewViewController) {
- _imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
- _imagePreviewViewController.presentingStyle = QMUIImagePreviewViewControllerTransitioningStyleZoom;// 将 present 动画改为 zoom,也即从某个位置放大到屏幕中央。默认样式为 fade。
- _imagePreviewViewController.imagePreviewView.delegate = self;// 将内部的图片查看器 delegate 指向当前 viewController,以获取要查看的图片数据
- // 当需要在退出大图预览时做一些事情的时候,可配合 UIViewController (QMUI) 的 qmui_visibleStateDidChangeBlock 来实现。
- _imagePreviewViewController.qmui_visibleStateDidChangeBlock = ^(QMUIImagePreviewViewController *viewController, QMUIViewControllerVisibleState visibleState) {
- if (visibleState == QMUIViewControllerWillDisappear) {
- // NSInteger exitAtIndex = viewController.imagePreviewView.currentImageIndex;
- }
- };
- self.imagePreviewViewController.sourceImageView = ^UIView *{
- @strongify(self)
- return self.mediaImg;
- };
- }
- return _imagePreviewViewController;
- }
- @end
|