ExerView.m 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. /**
  2. */
  3. #import "ExerView.h"
  4. #import <AVKit/AVKit.h>
  5. #import "CommentCell.h"
  6. #import <ZFPlayer/ZFAVPlayerManager.h>
  7. #import "RQYDTXCQuestionModule.h"
  8. @interface ExerView() <QMUIImagePreviewViewDelegate>
  9. //@interface ExerView()
  10. @property(nonatomic,strong)UILabel* lbl00;
  11. @property(nonatomic,strong)UILabel* lbl01;
  12. @property(nonatomic,strong)UIImageView* mediaImg;
  13. @property(nonatomic,strong)AVPlayerViewController *movie;
  14. @property(nonatomic,strong)AVPlayer *player;
  15. @property(nonatomic,strong)AVPlayerItem *playerItem;
  16. @property(nonatomic,strong)UIButton* playBtn;
  17. @property (nonatomic, readwrite, strong) MPPlayerController *mpPlayer;
  18. @property (nonatomic, readwrite, strong) ZFPlayerController *zfPlayer;
  19. @property (nonatomic, readwrite, strong) UIImageView *containerView;
  20. @property(nonatomic,strong)CLButton* btn02;
  21. @property(nonatomic,strong)CLButton* btn03;
  22. @property(nonatomic,strong)CLButton* btn04;
  23. @property(nonatomic,strong)CLButton* btn05;
  24. @property(nonatomic,strong)UIButton* btnYes;
  25. /**正确答案视图
  26. */
  27. @property(nonatomic,strong)UIView* answerV10;
  28. @property(nonatomic,strong)UILabel* lbl11;
  29. @property(nonatomic,strong)UILabel* lbl12;
  30. @property(nonatomic,strong)UIImageView* imgV13;
  31. @property(nonatomic,strong)NSMutableArray* imgs;
  32. @property(nonatomic,strong)UILabel* lbl14;
  33. /**评论的数据源
  34. */
  35. @property(nonatomic,strong)NSArray* comments;
  36. /**
  37. */
  38. /**其实下面的内容,可以由headerView,和tableView,footerView组合。
  39. 只需要设置tableview的frame即可。
  40. 反正子view是添加到父类里面的,无所谓。
  41. */
  42. @property (nonatomic, readwrite, strong) QMUIImagePreviewViewController *imagePreviewViewController;
  43. @end
  44. /**底部的试题分析的cell的个数最大值。
  45. */
  46. #define cellCntMax 3
  47. @implementation ExerView
  48. {
  49. NSMutableArray* optBtns;
  50. UIView *header;
  51. UIButton *footer ,*foldBtn;
  52. UITableView *myTableView;
  53. CGFloat tableH;
  54. // NSInteger answ;
  55. }
  56. /***控件需要一次性创建。
  57. 可是frame需要动态设置
  58. */
  59. -(id)initWithFrame:(CGRect)frame{
  60. self = [super initWithFrame:frame];
  61. if (!self) {
  62. return nil;
  63. }
  64. [self setBackgroundColor:[UIColor whiteColor]];
  65. [self createSubViews];
  66. self.contentSize = SGSizeMake(0, 600);
  67. return self;
  68. }
  69. - (void)dealloc {
  70. if (self.zfPlayer) {
  71. [self.zfPlayer stop];
  72. self.zfPlayer = nil;
  73. }
  74. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
  75. }
  76. /**每次设置question都需要动态设置frame
  77. */
  78. -(void)setSubViewFrame{
  79. @weakify(self)
  80. if (self.zfPlayer) {
  81. [self.zfPlayer stop];
  82. self.zfPlayer = nil;
  83. }
  84. CGFloat lbl01Y = 0;
  85. CGFloat lbl01X = 20;
  86. CGFloat lbl01W = kSize.width - lbl01X*2;
  87. CGFloat lbl01H = [_lbl01.text heightForWid:lbl01W Font:myDelegate.optionFont]+20;
  88. CGRect frame01 = CGRectMake(lbl01X, lbl01Y, lbl01W, lbl01H);
  89. self.lbl01.frame = frame01;
  90. CGFloat mediaH = 0;
  91. // CGRect frameMe ;//= CGRectZero;
  92. /**0:无图 1:图片题 2:动画题
  93. */
  94. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  95. if (RQStringIsEmpty(_ydtQuestionModel.media_url)) {
  96. /// 无图
  97. _mediaImg.hidden = YES;
  98. // _movie.view.hidden = YES;
  99. _containerView.hidden = YES;
  100. } else {
  101. if ([_ydtQuestionModel.media_url containsString:@".webp"]) {
  102. // _movie.view.hidden = YES;
  103. _containerView.hidden = YES;
  104. _mediaImg.hidden = NO;
  105. CGFloat imgMX = 10;
  106. CGFloat imgMY = CGRectGetMaxY(frame01);
  107. CGFloat imgMW = kSize.width - 20;
  108. CGFloat imgMH = imgMW *0.5;
  109. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  110. _mediaImg.frame = frameMe;
  111. NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.sinaimg)? _ydtQuestionModel.sinaimg : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
  112. NSData *imageData = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
  113. NSString *imageStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  114. UIImage *subImage = [UIImage sd_imageWithData:[NSData dataWithBase64EncodedString:imageStr] scale:1 firstFrameOnly:YES];
  115. if (!RQObjectIsNil(subImage)) {
  116. if (RQ_COMMON_MANAGER.is_Online_Media_Image) {
  117. [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:subImage];
  118. } else {
  119. _mediaImg.image = subImage;
  120. }
  121. } else {
  122. [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:RQWebImagePlaceholder()];
  123. }
  124. mediaH = imgMH;
  125. } else if ([_ydtQuestionModel.media_url containsString:@".mp4"]) {
  126. // _movie.view.hidden = NO;
  127. _containerView.hidden = NO;
  128. _mediaImg.hidden = YES;
  129. CGFloat imgMX = 10;
  130. CGFloat imgMY = CGRectGetMaxY(frame01);
  131. CGFloat imgMW = kSize.width - 20;
  132. CGFloat imgMH = imgMW *0.5;
  133. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  134. self.containerView.frame = frameMe;
  135. @weakify(self)
  136. // self.mpPlayer = [[MPPlayerController alloc] initWithContainerView:self.containerView];
  137. NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.video_url)? _ydtQuestionModel.video_url : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
  138. NSData *data = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
  139. NSURL *moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
  140. if (!RQObjectIsNil(data)) {
  141. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  142. NSString *documentsDirectory = [paths objectAtIndex:0];
  143. NSString *path = [documentsDirectory stringByAppendingPathComponent:media_name];
  144. [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
  145. moveUrl = [NSURL fileURLWithPath:path];
  146. if (RQ_COMMON_MANAGER.is_Online_Media_Video) {
  147. moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
  148. }
  149. }
  150. // self.containerView.image = [self videoImageWithvideoURL:moveUrl];
  151. self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.containerView];
  152. self.zfPlayer.currentPlayerManager.view.backgroundColor = UIColor.clearColor;
  153. self.zfPlayer.assetURLs = @[moveUrl];
  154. if (self.index == 1) {
  155. [self.zfPlayer playTheIndex:0];
  156. } else if ([self.questions.lastObject isEqual:_ydtQuestionModel] || [self.questions.firstObject isEqual:_ydtQuestionModel]) {
  157. [self.zfPlayer playTheIndex:0];
  158. }
  159. /// 播放完成
  160. self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) {
  161. @strongify(self)
  162. [self.zfPlayer.currentPlayerManager replay];
  163. };
  164. self.zfPlayer.playerPlayTimeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) {
  165. NSLog(@"%f---%f",currentTime,duration);
  166. };
  167. // self.mpPlayer.playableArray = @[_ydtQuestionModel];
  168. // [self.mpPlayer playWithPlayable:_ydtQuestionModel];
  169. // _movie.view.frame = frameMe;
  170. // NSURL *url = [NSURL URLWithString:_ydtQuestionModel.media_url];
  171. // _playerItem = [[AVPlayerItem alloc] initWithURL:url];
  172. // _player = [AVPlayer playerWithPlayerItem:_playerItem];
  173. // _movie.player = _player;
  174. // if (_movie.readyForDisplay) {
  175. // [_player play];
  176. // }
  177. // //添加播放完成通知
  178. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
  179. mediaH = imgMH;
  180. } else {
  181. }
  182. }
  183. } else {
  184. if ([defUser.car_type isEqualToString:@"2"]) {
  185. if (0 == _question.media_type.intValue) {
  186. _mediaImg.hidden = YES;
  187. _movie.view.hidden = YES;
  188. }
  189. if (1 == self.question.media_type.intValue)
  190. {
  191. _movie.view.hidden = YES;
  192. _mediaImg.hidden = NO;
  193. CGFloat imgMX = 10;
  194. CGFloat imgMY = CGRectGetMaxY(frame01);
  195. CGFloat imgMW = kSize.width - 20;
  196. CGFloat imgMH = imgMW *0.5;
  197. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  198. _mediaImg.frame = frameMe;
  199. if ([_question.media containsString:@".webp"]) {
  200. NSString *path = [[NSBundle mainBundle] pathForResource:[[_question.media componentsSeparatedByString:@"."] firstObject] ofType:@"webp"];
  201. _mediaImg.image = [UIImage sd_imageWithWebPData:[NSData dataWithContentsOfFile:path]];
  202. } else {
  203. _mediaImg.image = [UIImage imageNamed:_question.media];
  204. }
  205. mediaH = imgMH;
  206. }
  207. if (2 == _question.media_type.intValue) {
  208. _movie.view.hidden = NO;
  209. _mediaImg.hidden = YES;
  210. CGFloat imgMX = 10;
  211. CGFloat imgMY = CGRectGetMaxY(frame01);
  212. CGFloat imgMW = kSize.width - 20;
  213. CGFloat imgMH = imgMW *0.5;
  214. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  215. _movie.view.frame = frameMe;
  216. NSString *file=[[NSBundle mainBundle]pathForResource:_question.media ofType:nil];
  217. NSURL *url=[NSURL fileURLWithPath:file];
  218. _playerItem = [[AVPlayerItem alloc] initWithURL:url];
  219. _player = [AVPlayer playerWithPlayerItem:_playerItem];
  220. _movie.player = _player;
  221. if (_movie.readyForDisplay) {
  222. [_player play];
  223. }
  224. //添加播放完成通知
  225. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
  226. mediaH = imgMH;
  227. }
  228. } else {
  229. if (RQStringIsEmpty(_ydtQuestionModel.media_url)) {
  230. /// 无图
  231. _mediaImg.hidden = YES;
  232. // _movie.view.hidden = YES;
  233. _containerView.hidden = YES;
  234. } else {
  235. if ([_ydtQuestionModel.media_url containsString:@".webp"]) {
  236. // _movie.view.hidden = YES;
  237. _containerView.hidden = YES;
  238. _mediaImg.hidden = NO;
  239. CGFloat imgMX = 10;
  240. CGFloat imgMY = CGRectGetMaxY(frame01);
  241. CGFloat imgMW = kSize.width - 20;
  242. CGFloat imgMH = imgMW *0.5;
  243. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  244. _mediaImg.frame = frameMe;
  245. NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.sinaimg)? _ydtQuestionModel.sinaimg : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
  246. NSData *imageData = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
  247. NSString *imageStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  248. // NSData *subImageData = [[NSData alloc] initWithBase64EncodedString:imageStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  249. UIImage *subImage = [UIImage sd_imageWithData:[NSData dataWithBase64EncodedString:imageStr] scale:1 firstFrameOnly:YES];
  250. if (!RQObjectIsNil(subImage)) {
  251. if (RQ_COMMON_MANAGER.is_Online_Media_Image) {
  252. [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:subImage];
  253. } else {
  254. _mediaImg.image = subImage;
  255. }
  256. } else {
  257. [_mediaImg sd_setImageWithURL:[NSURL URLWithString:_ydtQuestionModel.media_url] placeholderImage:RQWebImagePlaceholder()];
  258. }
  259. mediaH = imgMH;
  260. } else if ([_ydtQuestionModel.media_url containsString:@".mp4"]) {
  261. // _movie.view.hidden = NO;
  262. _containerView.hidden = NO;
  263. _mediaImg.hidden = YES;
  264. CGFloat imgMX = 10;
  265. CGFloat imgMY = CGRectGetMaxY(frame01);
  266. CGFloat imgMW = kSize.width - 20;
  267. CGFloat imgMH = imgMW *0.5;
  268. CGRect frameMe = CGRectMake(imgMX, imgMY, imgMW, imgMH);
  269. self.containerView.frame = frameMe;
  270. @weakify(self)
  271. // self.mpPlayer = [[MPPlayerController alloc] initWithContainerView:self.containerView];
  272. NSString *media_name = RQStringIsNotEmpty(_ydtQuestionModel.video_url)? _ydtQuestionModel.video_url : [_ydtQuestionModel.media_url componentsSeparatedByString:@"/"].lastObject;
  273. NSData *data = [RQ_YDTQuestion_Module getMediaDataWithMediaName:media_name];
  274. NSURL *moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
  275. if (!RQObjectIsNil(data)) {
  276. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  277. NSString *documentsDirectory = [paths objectAtIndex:0];
  278. NSString *path = [documentsDirectory stringByAppendingPathComponent:media_name];
  279. [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
  280. moveUrl = [NSURL fileURLWithPath:path];
  281. if (RQ_COMMON_MANAGER.is_Online_Media_Video) {
  282. moveUrl = [NSURL URLWithString:_ydtQuestionModel.media_url];
  283. }
  284. }
  285. // self.containerView.image = [self videoImageWithvideoURL:moveUrl];
  286. self.zfPlayer = [[ZFPlayerController alloc] initWithPlayerManager:[[ZFAVPlayerManager alloc] init] containerView:self.containerView];
  287. self.zfPlayer.currentPlayerManager.view.backgroundColor = UIColor.clearColor;
  288. self.zfPlayer.assetURLs = @[moveUrl];
  289. if (self.index == 1) {
  290. [self.zfPlayer playTheIndex:0];
  291. } else if ([self.questions.lastObject isEqual:_ydtQuestionModel] || [self.questions.firstObject isEqual:_ydtQuestionModel]) {
  292. [self.zfPlayer playTheIndex:0];
  293. }
  294. /// 播放完成
  295. self.zfPlayer.playerDidToEnd = ^(id _Nonnull asset) {
  296. @strongify(self)
  297. [self.zfPlayer.currentPlayerManager replay];
  298. };
  299. self.zfPlayer.playerPlayTimeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) {
  300. NSLog(@"%f---%f",currentTime,duration);
  301. };
  302. // self.mpPlayer.playableArray = @[_ydtQuestionModel];
  303. // [self.mpPlayer playWithPlayable:_ydtQuestionModel];
  304. // _movie.view.frame = frameMe;
  305. // NSURL *url = [NSURL URLWithString:_ydtQuestionModel.media_url];
  306. // _playerItem = [[AVPlayerItem alloc] initWithURL:url];
  307. // _player = [AVPlayer playerWithPlayerItem:_playerItem];
  308. // _movie.player = _player;
  309. // if (_movie.readyForDisplay) {
  310. // [_player play];
  311. // }
  312. // //添加播放完成通知
  313. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(runLoopTheMovie:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
  314. mediaH = imgMH;
  315. } else {
  316. }
  317. }
  318. }
  319. }
  320. /**A
  321. */
  322. CGFloat btn02X =0;
  323. CGFloat btn02Y =CGRectGetMaxY(frame01) + mediaH +kCellBd ;
  324. CGFloat btn02W =kSize.width;
  325. CGFloat btn02H =40.0;
  326. CGRect frame02 = CGRectMake(btn02X, btn02Y, btn02W, btn02H);
  327. self.btn02.frame = frame02;
  328. // CLButton* btn;
  329. /**B
  330. */
  331. CGFloat btn03X =0;
  332. CGFloat btn03Y =CGRectGetMaxY(frame02)+kCellBd;
  333. CGFloat btn03W =kSize.width;
  334. CGFloat btn03H =40.0;
  335. CGRect frame03 = CGRectMake(btn03X, btn03Y, btn03W, btn03H);
  336. self.btn03.frame = frame03;
  337. /**C
  338. */
  339. CGFloat btn04X =0;
  340. CGFloat btn04Y =CGRectGetMaxY(frame03)+kCellBd;
  341. CGFloat btn04W =kSize.width;
  342. CGFloat btn04H =40.0;
  343. CGRect frame04 = CGRectMake(btn04X, btn04Y, btn04W, btn04H);
  344. self.btn04.frame = frame04;
  345. /**D
  346. */
  347. CGFloat btn05X =0;
  348. CGFloat btn05Y =CGRectGetMaxY(frame04)+kCellBd;
  349. CGFloat btn05W =kSize.width;
  350. CGFloat btn05H =40.0;
  351. CGRect frame05 = CGRectMake(btn05X, btn05Y, btn05W, btn05H);
  352. self.btn05.frame = frame05;
  353. CGFloat x,y,h,w;
  354. x = 80;
  355. w = kSize.width - x*2;
  356. y = btn05Y + btn05H + 30;
  357. h = 55;
  358. _btnYes.frame = CGRectMake(x, y, w, h);
  359. CGFloat ansVX = 0;
  360. CGFloat ansVY = 0;
  361. /**如果是判断题
  362. */
  363. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  364. if (_ydtQuestionModel.Type == 1) {
  365. ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
  366. } else {
  367. ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
  368. }
  369. } else {
  370. if ([defUser.car_type isEqualToString:@"2"]) {
  371. if (0 == _question.option_type.intValue) {
  372. ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
  373. }else{
  374. ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
  375. }
  376. } else {
  377. if (_ydtQuestionModel.Type == 1) {
  378. ansVY = CGRectGetMaxY(frame03) + kSecHeadHeight;
  379. } else {
  380. ansVY = CGRectGetMaxY(frame05) + kSecHeadHeight;
  381. }
  382. }
  383. }
  384. CGFloat ansVW = kSize.width;
  385. CGFloat ansVH = 500;
  386. CGRect frameAnV = CGRectMake(ansVX, ansVY, ansVW, ansVH);
  387. self.answerV10.frame = frameAnV;
  388. CGFloat lbl11X = 10;
  389. CGFloat lbl11Y = kSecHeadHeight;
  390. CGFloat lbl11W = 150;
  391. CGFloat lbl11H = 30;
  392. CGRect frame11 = CGRectMake(lbl11X, lbl11Y, lbl11W, lbl11H);
  393. self.lbl11.text = @"最佳解释";
  394. self.lbl11.frame = frame11;
  395. self.lbl11.textColor = defGreen;
  396. // UILabel* label;
  397. CGFloat img13H = 20;
  398. CGFloat img13W = img13H*5;
  399. CGFloat img13Y = kSecHeadHeight;
  400. CGFloat img13X = kSize.width - img13W - 10;
  401. CGRect frame13 = CGRectMake(img13X, img13Y, img13W, img13H);
  402. self.imgV13.frame = frame13;
  403. // int i=0;
  404. // for (UIImageView* iv in _imgs)
  405. // {
  406. // iv.frame = CGRectMake(img13X + img13W/5*i, img13Y+5, img13H -3, img13H-3);
  407. // iv.image = [UIImage imageNamed:@"rankstar0_img.png"];
  408. // i++;
  409. // }
  410. // CGFloat lbl12W = 60;
  411. // CGFloat lbl12H = 30;
  412. // CGFloat lbl12X = CGRectGetMinX(frame13) - lbl12W;
  413. // CGFloat lbl12Y = kSecHeadHeight;
  414. // CGRect frame12 = CGRectMake(lbl12X, lbl12Y, lbl12W, lbl12H);
  415. self.lbl12.text = @"难度";
  416. // self.lbl12.frame = frame12;
  417. /**解释
  418. */
  419. CGFloat lbl14X = 10;
  420. CGFloat lbl14Y = CGRectGetMaxY(frame11) + kSecHeadHeight;
  421. CGFloat lbl14W = kSize.width - lbl14X*2;
  422. CGFloat lbl14H = [_lbl14.text heightForWid:lbl14W Font:myDelegate.optionFont]+20;
  423. CGRect frame14 = CGRectMake(lbl14X, lbl14Y, lbl14W, lbl14H);
  424. self.lbl14.frame = frame14;
  425. CGFloat currentTop = lbl14Y + lbl14H;
  426. [header setFrame:CGRectMake(0, currentTop + 10, kSize.width, 30)];
  427. currentTop +=55;
  428. [myTableView setFrame:CGRectMake(0, currentTop , kSize.width, tableH)];
  429. [footer setFrame:CGRectMake(0, currentTop + tableH, kSize.width, 40)];
  430. [myTableView setBackgroundColor:[UIColor clearColor]];
  431. _answerV10.height = footer.bottom;
  432. if (_answerV10.hidden) {
  433. [self setContentSize:kSize];
  434. }else{
  435. [self setContentSize:CGSizeMake(0,_answerV10.bottom+100)];
  436. }
  437. }
  438. -(void)createSubViews
  439. {
  440. _comments = [NSArray array];
  441. UILabel* lbl01 = [[UILabel alloc] init];
  442. lbl01.font = [UIFont scaleSize:myDelegate.optionFont];
  443. lbl01.textColor = [UIColor grayColor];
  444. lbl01.numberOfLines = 0;
  445. [self addSubview:lbl01];
  446. self.lbl01 = lbl01;
  447. UILabel* lbl00 = [[UILabel alloc] init];
  448. self.lbl00 = lbl00;
  449. _mediaImg = [[UIImageView alloc] init];
  450. [_mediaImg setContentMode:UIViewContentModeScaleAspectFit];
  451. [_mediaImg setClipsToBounds:YES];
  452. [_mediaImg setBackgroundColor:[UIColor clearColor]];
  453. [self addSubview:_mediaImg];
  454. //图片题放大
  455. [_mediaImg setUserInteractionEnabled:YES];
  456. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(magnifyImage)];
  457. //把手势添加到指定视图上
  458. [_mediaImg addGestureRecognizer:tapGesture];
  459. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  460. [self addSubview:self.containerView];
  461. } else {
  462. if ([defUser.car_type isEqualToString:@"2"]) {
  463. _movie = [[AVPlayerViewController alloc] init];
  464. _movie.showsPlaybackControls = NO;
  465. [self addSubview:_movie.view];
  466. } else {
  467. [self addSubview:self.containerView];
  468. }
  469. }
  470. optBtns = [NSMutableArray array];
  471. /**A
  472. */
  473. CLButton* btn02= [[CLButton alloc] init];
  474. btn02.imgN = @"option_A.png";
  475. [optBtns addObject:btn02];
  476. self.btn02 = btn02;
  477. btn02.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 1 *10000 : ([defUser.car_type isEqualToString:@"2"]? 16 : 1 *10000);
  478. [self addSubview:btn02];
  479. [btn02 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
  480. CLButton* btn;
  481. btn = self.btn02;
  482. [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
  483. /**B
  484. */
  485. CLButton* btn03= [[CLButton alloc] init];
  486. self.btn03 = btn03;
  487. btn03.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 2 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 32 : 2 * 10000);
  488. btn03.imgN = @"option_B.png";
  489. [self addSubview:btn03];
  490. [btn03 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
  491. [optBtns addObject:btn03]; btn = self.btn03;
  492. [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
  493. /**C
  494. */
  495. CLButton* btn04= [[CLButton alloc] init];
  496. [btn04 setImage:defaultImg forState:UIControlStateNormal];
  497. self.btn04 = btn04;
  498. btn04.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 3 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 64 : 3 * 10000);
  499. btn04.imgN = @"option_C.png";
  500. [self addSubview:btn04];
  501. [btn04 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
  502. [optBtns addObject:btn04];
  503. btn = self.btn04;
  504. [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
  505. /**D
  506. */
  507. CLButton* btn05= [[CLButton alloc] init];
  508. self.btn05 = btn05;
  509. btn05.tag = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 4 * 10000 : ([defUser.car_type isEqualToString:@"2"]? 128 : 4 * 10000);
  510. btn05.imgN = @"option_D.png";
  511. [self addSubview:btn05];
  512. [btn05 addTarget:self action:@selector(AAction:) forControlEvents:UIControlEventTouchUpInside];
  513. [optBtns addObject:btn05];
  514. btn = self.btn05;
  515. [btn addSelfViewWithRect:CGRectMake(0, 0, kSize.width, .5) Color:KlineColor];
  516. _btnYes = [[UIButton alloc] init];
  517. [_btnYes setBackgroundColor:KlineColor];
  518. [_btnYes setTitle:@"确定" textColor:subTitleColor font:22 fotState:UIControlStateNormal];
  519. [_btnYes addTarget:self action:@selector(multiOptsYes:) forControlEvents:UIControlEventTouchUpInside];
  520. _btnYes.layer.cornerRadius = 10;
  521. [self addSubview:_btnYes];
  522. UIView* view10 = [[UIView alloc] init];
  523. self.answerV10 = view10;
  524. [self addSubview:view10];
  525. self.lbl11 = [[UILabel alloc] init];
  526. [self.answerV10 addSubview:self.lbl11];
  527. UILabel* label = self.lbl11;
  528. [label addSelfViewWithRect:CGRectMake(-10, -12, kSize.width, 8) Color:KlineColor];
  529. self.lbl12 = [[UILabel alloc] init];
  530. [self.answerV10 addSubview:self.lbl12];
  531. self.imgV13 = [[UIImageView alloc] init];
  532. [self.answerV10 addSubview:self.imgV13];
  533. //解释。label
  534. self.lbl14 = [[UILabel alloc] init];
  535. [self.answerV10 addSubview:self.lbl14];
  536. label = self.lbl14;
  537. [label setFont:[UIFont scaleSize:myDelegate.optionFont]];
  538. [label addSelfViewWithRect:CGRectMake(-10, -10, kSize.width, .5) Color:KlineColor];
  539. _imgs = [NSMutableArray array];
  540. for (int i=0; i<5; i++) {
  541. UIImageView *iv = [[UIImageView alloc] init];
  542. [_imgs addObject:iv];
  543. [self.answerV10 addSubview:iv];
  544. }
  545. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  546. } else {
  547. myTableView = [[UITableView alloc] init];
  548. [myTableView setDataSource:self];
  549. [myTableView setDelegate:self];
  550. myTableView.separatorInset = UIEdgeInsetsMake(0,70, 0, 10);
  551. [self.answerV10 addSubview:myTableView];
  552. tableH = 0;
  553. //header
  554. UIView* vi = [[UIView alloc] initWithFrame:SGRectMake(0, 0, 320, 25)];
  555. [_answerV10 addSubview:vi];
  556. label = [[UILabel alloc] initWithFrame:SGRectMake(10, 0, 80, 25)];
  557. [label setText:@"试题分析"];
  558. [label setTextColor:contentTextColor];
  559. [vi addSubview:label];
  560. header = vi;
  561. [label addSelfViewWithRect:SGRectMake(-10, -10, 320, 7) Color:KlineColor];
  562. [label addSelfViewWithRect:SGRectMake(-10, 26, 320, .5) Color:KlineColor];
  563. /**普通状态显示展开。选定状态显示收起
  564. */
  565. UIButton* btnn;
  566. btnn = [[UIButton alloc] initWithFrame:SGRectMake(90, 0, 80, 25)];
  567. [btnn setTitle:@"展开" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  568. [btnn setTitle:@"收起" textColor:defGreen font:NormalFont fotState:UIControlStateSelected];
  569. [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
  570. [vi addSubview:btnn];
  571. [btnn setTag:0];
  572. foldBtn = btnn;
  573. btnn = [[UIButton alloc] initWithFrame:SGRectMake(320-90, 2.5, 80, 20)];
  574. [btnn setTitle:@"我来分析" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  575. [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
  576. [btnn setBoardWid:.5 Color:defGreen];
  577. [vi addSubview:btnn];
  578. [btnn setTag:1];
  579. btnn = [[UIButton alloc] init];
  580. [btnn setTitle:@"查看全部学员分析" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  581. [btnn addTarget:self action:@selector(btnHereClick:) forControlEvents:UIControlEventTouchUpInside];
  582. [_answerV10 addSubview:btnn];
  583. footer = btnn;
  584. [btnn addSelfViewWithRect:SGRectMake(0, 40, 320, .5) Color:KlineColor];
  585. [btnn setTag:2];
  586. [myTableView setHidden:YES];
  587. [footer setHidden:YES];
  588. }
  589. }
  590. #pragma mark - 接收播放完成的通知
  591. - (void)runLoopTheMovie:(NSNotification *)notification {
  592. AVPlayerItem *playerItem = notification.object;
  593. [playerItem seekToTime:kCMTimeZero];
  594. [_player play];
  595. }
  596. //图片放大
  597. - (void)magnifyImage {
  598. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  599. [RQControllerHelper.currentViewController presentViewController:self.imagePreviewViewController animated:YES completion:nil];
  600. } else {
  601. if ([defUser.car_type isEqualToString:@"2"]) {
  602. [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:@[_mediaImg.image] currentIndex:0 isCanSave:NO];
  603. } else {
  604. [RQControllerHelper.currentViewController presentViewController:self.imagePreviewViewController animated:YES completion:nil];
  605. }
  606. }
  607. }
  608. - (void)setQuestion:(Question *)question {
  609. if(!question){
  610. return;
  611. }
  612. self.comments = nil;
  613. [myTableView reloadData];
  614. [foldBtn setSelected:NO];
  615. [myTableView setHidden:YES];
  616. [footer setHidden:YES];
  617. _btnYes.enabled = NO;
  618. [self setContentOffset:CGPointMake(0, 0)];
  619. _playBtn.hidden = YES;
  620. self.answerV10.hidden = YES;
  621. _question = question;
  622. for (UIButton* btn in optBtns) {
  623. [btn setSelected:NO];
  624. [btn setBackgroundColor:[UIColor clearColor]];
  625. }
  626. switch (question.option_type.intValue) {
  627. case 0:
  628. self.lbl00.text = @"判断";
  629. self.btn04.hidden = YES;
  630. self.btn05.hidden = YES;
  631. _btnYes.hidden = YES;
  632. break;
  633. case 1:
  634. self.lbl00.text = @"单选";
  635. self.btn04.hidden = NO;
  636. self.btn05.hidden = NO;
  637. _btnYes.hidden = YES;
  638. break;
  639. case 2:
  640. self.lbl00.text = @"多选";
  641. self.btn04.hidden = NO;
  642. self.btn05.hidden = NO;
  643. _btnYes.hidden = NO;
  644. break;
  645. default:
  646. break;
  647. }
  648. self.lbl01.text = [NSString stringWithFormat:@" %@:%@",self.lbl00.text,question.question];
  649. [self.btn02 setTitle:question.optionA forState:UIControlStateNormal];
  650. [self.btn03 setTitle:question.optionB forState:UIControlStateNormal];
  651. [self.btn04 setTitle:question.optionC forState:UIControlStateNormal];
  652. [self.btn05 setTitle:question.optionD forState:UIControlStateNormal];
  653. self.btn02.hidden = !question.optionA || [question.optionA isEqualToString:@""];
  654. self.btn03.hidden = !question.optionB || [question.optionB isEqualToString:@""];
  655. self.btn04.hidden = !question.optionC || [question.optionC isEqualToString:@""];
  656. self.btn05.hidden = !question.optionD || [question.optionD isEqualToString:@""];
  657. /**
  658. 选项字体 一键设置
  659. */
  660. [self.lbl01 setFont:[UIFont scaleSize:myDelegate.optionFont]];
  661. [self.btn02.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  662. [self.btn03.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  663. [self.btn04.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  664. [self.btn05.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  665. _btn02.imgN = @"option_A.png";
  666. _btn03.imgN = @"option_B.png";
  667. _btn04.imgN = @"option_C.png";
  668. _btn05.imgN = @"option_D.png";
  669. for (CLButton* btn in optBtns)
  670. {
  671. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  672. }
  673. [self.lbl14 setFont:[UIFont scaleSize:myDelegate.optionFont]];
  674. self.lbl14.numberOfLines = 0;
  675. self.lbl14.text = _question.explain;
  676. [self setSubViewFrame];
  677. }
  678. - (void)setYdtQuestionModel:(RQYDTQuestionModel *)ydtQuestionModel
  679. {
  680. if(!ydtQuestionModel){
  681. return;
  682. }
  683. self.comments = nil;
  684. [myTableView reloadData];
  685. [foldBtn setSelected:NO];
  686. [myTableView setHidden:YES];
  687. [footer setHidden:YES];
  688. _btnYes.enabled = NO;
  689. [self setContentOffset:CGPointMake(0, 0)];
  690. _playBtn.hidden = YES;
  691. self.answerV10.hidden = YES;
  692. _ydtQuestionModel = ydtQuestionModel;
  693. for (UIButton* btn in optBtns) {
  694. [btn setSelected:NO];
  695. [btn setBackgroundColor:[UIColor clearColor]];
  696. }
  697. switch (_ydtQuestionModel.Type) {
  698. case 1:
  699. self.lbl00.text = @"判断";
  700. self.btn04.hidden = YES;
  701. self.btn05.hidden = YES;
  702. _btnYes.hidden = YES;
  703. break;
  704. case 2:
  705. self.lbl00.text = @"单选";
  706. self.btn04.hidden = NO;
  707. self.btn05.hidden = NO;
  708. _btnYes.hidden = YES;
  709. break;
  710. case 3:
  711. self.lbl00.text = @"多选";
  712. self.btn04.hidden = NO;
  713. self.btn05.hidden = NO;
  714. _btnYes.hidden = NO;
  715. break;
  716. default:
  717. break;
  718. }
  719. self.lbl01.text = [NSString stringWithFormat:@" %@:%@",self.lbl00.text,_ydtQuestionModel.Question];
  720. [self.btn02 setTitle:(_ydtQuestionModel.Type == 1)? @"正确" : _ydtQuestionModel.An1 forState:UIControlStateNormal];
  721. [self.btn03 setTitle:(_ydtQuestionModel.Type == 1)? @"错误" : _ydtQuestionModel.An2 forState:UIControlStateNormal];
  722. [self.btn04 setTitle:_ydtQuestionModel.An3 forState:UIControlStateNormal];
  723. [self.btn05 setTitle:_ydtQuestionModel.An4 forState:UIControlStateNormal];
  724. // self.btn02.hidden = !ydtQuestionModel.An1 || [ydtQuestionModel.An1 isEqualToString:@""];
  725. // self.btn03.hidden = !ydtQuestionModel.An2 || [ydtQuestionModel.An2 isEqualToString:@""];
  726. self.btn04.hidden = !ydtQuestionModel.An3 || [ydtQuestionModel.An3 isEqualToString:@""];
  727. self.btn05.hidden = !ydtQuestionModel.An4 || [ydtQuestionModel.An4 isEqualToString:@""];
  728. /**
  729. 选项字体 一键设置
  730. */
  731. [self.lbl01 setFont:[UIFont scaleSize:myDelegate.optionFont]];
  732. [self.btn02.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  733. [self.btn03.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  734. [self.btn04.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  735. [self.btn05.titleLabel setFont:[UIFont scaleSize:myDelegate.optionFont]];
  736. _btn02.imgN = @"option_A.png";
  737. _btn03.imgN = @"option_B.png";
  738. _btn04.imgN = @"option_C.png";
  739. _btn05.imgN = @"option_D.png";
  740. for (CLButton* btn in optBtns)
  741. {
  742. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  743. }
  744. [self.lbl14 setFont:[UIFont scaleSize:myDelegate.optionFont]];
  745. self.lbl14.numberOfLines = 0;
  746. self.lbl14.text = _ydtQuestionModel.explain;
  747. [self setSubViewFrame];
  748. }
  749. //改变背景颜色 实现夜间模式
  750. -(void)setNightMode:(BOOL)isNight
  751. {
  752. if (isNight)
  753. {
  754. [self setBackgroundColor:nightColor];//[UIColor orangeColor]
  755. }
  756. else
  757. {
  758. [self setBackgroundColor:[UIColor whiteColor]];
  759. }
  760. }
  761. #pragma mark -
  762. -(void)getAllComments
  763. {
  764. @weakify(self)
  765. if (![Util connectedToNetWork]) {
  766. showMsgUnconnect();
  767. return;
  768. }
  769. NSMutableArray *arr=[NSMutableArray array];
  770. [arr property:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? @(_ydtQuestionModel.ID) : ([defUser.car_type isEqualToString:@"2"]? _question._id : @(_ydtQuestionModel.ID)) forKey:@"id"];
  771. [arr property:@"1" forKey:@"isPage"];
  772. [arr property:@"7" forKey:@"pageSize"];
  773. [arr property:@"1" forKey:@"currentPage"];
  774. NSString* method = @"getQuestionComments";
  775. [MBProgressHUD showLoadToView:self];
  776. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  777. @strongify(self)
  778. [MBProgressHUD hideHUDForView:self];
  779. if (!dict) {
  780. ShowMsgFailed();
  781. return;
  782. }
  783. if ([dict[@"code"] isEqualToString:@"1"])
  784. {
  785. ShowMsg(dict[@"body"]);
  786. return;
  787. }
  788. _comments = dict[@"body"];
  789. if (![dict[@"body"] isKindOfClass:[NSArray class]]) {
  790. _comments = @[];
  791. }
  792. if (_comments.count < 1) {
  793. ShowMsg(@"暂无相关评论");
  794. }
  795. /*题目分析 剩下两个找不到(你晚上看看)
  796. PHOTO = "";
  797. "QC_CRDATE" = "2017-01-23 16:08:44";
  798. "QC_DESC" = gdfgfd;
  799. "QC_DOWN_NUM" = 0;
  800. "QC_ID" = 61;
  801. "QC_QID" = 1;
  802. "QC_TYPE" = 1;
  803. "QC_UP_NUM" = 0;
  804. "QC_USER_ID" = 1;
  805. */
  806. tableH = 0;
  807. for (int i=0; i< _comments.count && i < cellCntMax; i++) {
  808. NSDictionary *dic = _comments[i];
  809. tableH += 105 + [dic[@"QC_DESC"] heightForWid:(kSize.width - 80) Font:15];
  810. }
  811. // [footer setTitle:[NSString stringWithFormat:@"查看全部%d位学员分析",(int)_comments.count] textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  812. [myTableView reloadData];
  813. [self setSubViewFrame];
  814. }];
  815. }
  816. -(void)showComments:(BOOL)isShow
  817. {
  818. if (isShow) {
  819. }else{
  820. }
  821. }
  822. -(void)btnHereClick:(UIButton*)sender{
  823. if (0 == sender.tag)
  824. {
  825. [myTableView setHidden:sender.selected];
  826. [footer setHidden:sender.selected];
  827. sender.selected = !sender.selected;
  828. if (sender.selected) {
  829. [self getAllComments];
  830. }
  831. }else{
  832. [self.delegate2 gotoAllCommentVC];
  833. }
  834. }
  835. -(void)setShowAnswer:(BOOL)showAnswer
  836. {
  837. [_answerV10 setHidden:!showAnswer];
  838. }
  839. -(void)playMovie
  840. {
  841. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  842. if (RQStringIsNotEmpty(_ydtQuestionModel.video_url)) {
  843. [self.mpPlayer playWithPlayable:_ydtQuestionModel];
  844. }
  845. } else {
  846. if ([defUser.car_type isEqualToString:@"2"]) {
  847. if (_question.media_type.intValue == 2)
  848. {
  849. [_player play];
  850. }
  851. } else {
  852. if (RQStringIsNotEmpty(_ydtQuestionModel.video_url)) {
  853. [self.mpPlayer playWithPlayable:_ydtQuestionModel];
  854. }
  855. }
  856. }
  857. }
  858. -(void)stopMovie
  859. {
  860. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  861. } else {
  862. if ([defUser.car_type isEqualToString:@"2"]) {
  863. [_player pause];
  864. }
  865. }
  866. if (self.zfPlayer) {
  867. [self.zfPlayer stop];
  868. self.zfPlayer = nil;
  869. }
  870. }
  871. /**4个按钮用tag来区分。16,32,64,128
  872. 当点击按钮后,设置正确答案的img
  873. 如果答题错误,把点的按钮变成错误的img
  874. 不管是否正确都要跳出正确答案,
  875. */
  876. -(void)AAction:(CLButton*)sender
  877. {
  878. int type = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? _ydtQuestionModel.Type : ([defUser.car_type isEqualToString:@"2"]? _question.option_type.intValue : _ydtQuestionModel.Type);
  879. if (type == (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 3 : ([defUser.car_type isEqualToString:@"2"]? 2 : 3))) {
  880. sender.selected = !sender.selected;
  881. if (sender.selected) {
  882. [sender setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];//backGroundColor
  883. }else{
  884. [sender setBackgroundColor:[UIColor clearColor]];
  885. }
  886. int optCnt = 0;
  887. for (int i=0; i<4; i++)
  888. {
  889. UIButton* btn = optBtns[i];
  890. if (btn.selected) {
  891. optCnt++;
  892. }
  893. }
  894. if (optCnt > 1) {
  895. _btnYes.enabled = YES;
  896. [_btnYes setBackgroundColor:defGreen];
  897. }else{
  898. _btnYes.enabled = NO;
  899. [_btnYes setBackgroundColor:KlineColor];
  900. }
  901. return;
  902. }
  903. if ([self.delegate2 respondsToSelector:@selector(didChooseOption:isRight:)]) {
  904. [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)))];
  905. }
  906. [self choose:sender.tag];
  907. return;
  908. }
  909. /**展示答案的权利,交给exVC。这里就不去设置了。
  910. 这里主要是根据。opt设置按钮的图片。
  911. */
  912. -(void)choose:(NSInteger)opt
  913. {
  914. _btn02.enabled = NO;
  915. _btn03.enabled = NO;
  916. _btn04.enabled = NO;
  917. _btn05.enabled = NO;
  918. _btnYes.hidden = YES;
  919. int type = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? _ydtQuestionModel.Type : ([defUser.car_type isEqualToString:@"2"]? _question.option_type.intValue : _ydtQuestionModel.Type);
  920. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  921. if ( 3 == type) {
  922. NSString* answer = _ydtQuestionModel.AnswerTrue;
  923. NSString* myAnswer = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:opt]];
  924. NSArray* arr = @[@"1",@"2",@"3",@"4"];
  925. for (int i = 0; i < 4; i++) {
  926. CLButton* btn = optBtns[i];
  927. NSRange range = [answer rangeOfString:arr[i]];
  928. NSRange myRange = [myAnswer rangeOfString:arr[i]];
  929. BOOL isSel = (myRange.location != NSNotFound);
  930. BOOL isRig = (range.location != NSNotFound);
  931. if (isSel) {
  932. [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];
  933. }else{
  934. [btn setBackgroundColor:[UIColor clearColor]];
  935. }
  936. if (isRig) {
  937. btn.imgN = @"question_correct.png";
  938. }else if (isSel){
  939. btn.imgN = @"question_error.png";
  940. }
  941. }
  942. return;
  943. }
  944. for (CLButton* btn in optBtns) {
  945. if (_ydtQuestionModel.AnswerTrue.intValue == (btn.tag / 10000))
  946. {
  947. btn.imgN = @"question_correct.png";
  948. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  949. }
  950. }
  951. if ((opt / 10000) != _ydtQuestionModel.AnswerTrue.intValue) {
  952. switch (opt / 10000) {
  953. case 1:
  954. _btn02.imgN = @"question_error.png";
  955. break;
  956. case 2:
  957. _btn03.imgN = @"question_error.png";
  958. break;
  959. case 3:
  960. _btn04.imgN = @"question_error.png";
  961. break;
  962. case 4:
  963. _btn05.imgN = @"question_error.png";
  964. break;
  965. default:
  966. break;
  967. }
  968. }
  969. } else {
  970. if ([defUser.car_type isEqualToString:@"2"]) {
  971. if ( 2 == type) {
  972. NSString* answer = [Util getAnswerByTen:_question.answer.intValue];
  973. NSString* myAnswer = [Util getAnswerByTen:opt];
  974. NSArray* arr = @[@"A",@"B",@"C",@"D"];
  975. for (int i = 0; i < 4; i++) {
  976. CLButton* btn = optBtns[i];
  977. NSRange range = [answer rangeOfString:arr[i]];
  978. NSRange myRange = [myAnswer rangeOfString:arr[i]];
  979. BOOL isSel = (myRange.location != NSNotFound);
  980. BOOL isRig = (range.location != NSNotFound);
  981. if (isSel) {
  982. [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];//klinecolor
  983. }else{
  984. [btn setBackgroundColor:[UIColor clearColor]];
  985. }
  986. if (isRig) {
  987. btn.imgN = @"question_correct.png";
  988. }else if (isSel){
  989. btn.imgN = @"question_error.png";
  990. }
  991. }
  992. return;
  993. }
  994. for (CLButton* btn in optBtns) {
  995. if (_question.answer.intValue == btn.tag)
  996. {
  997. btn.imgN = @"question_correct.png";
  998. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  999. }
  1000. }
  1001. if (opt != _question.answer.intValue) {
  1002. switch (opt) {
  1003. case 16:
  1004. _btn02.imgN = @"question_error.png";
  1005. break;
  1006. case 32:
  1007. _btn03.imgN = @"question_error.png";
  1008. break;
  1009. case 64:
  1010. _btn04.imgN = @"question_error.png";
  1011. break;
  1012. case 128:
  1013. _btn05.imgN = @"question_error.png";
  1014. break;
  1015. default:
  1016. break;
  1017. }
  1018. }
  1019. } else {
  1020. if ( 3 == type) {
  1021. NSString* answer = _ydtQuestionModel.AnswerTrue;
  1022. NSString* myAnswer = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:opt]];
  1023. NSArray* arr = @[@"1",@"2",@"3",@"4"];
  1024. for (int i = 0; i < 4; i++) {
  1025. CLButton* btn = optBtns[i];
  1026. NSRange range = [answer rangeOfString:arr[i]];
  1027. NSRange myRange = [myAnswer rangeOfString:arr[i]];
  1028. BOOL isSel = (myRange.location != NSNotFound);
  1029. BOOL isRig = (range.location != NSNotFound);
  1030. if (isSel) {
  1031. [btn setBackgroundColor:RGBA_COLOR(134, 204, 71, 0.5)];
  1032. }else{
  1033. [btn setBackgroundColor:[UIColor clearColor]];
  1034. }
  1035. if (isRig) {
  1036. btn.imgN = @"question_correct.png";
  1037. }else if (isSel){
  1038. btn.imgN = @"question_error.png";
  1039. }
  1040. }
  1041. return;
  1042. }
  1043. for (CLButton* btn in optBtns) {
  1044. if (_ydtQuestionModel.AnswerTrue.intValue == (btn.tag / 10000))
  1045. {
  1046. btn.imgN = @"question_correct.png";
  1047. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  1048. }
  1049. }
  1050. if ((opt / 10000) != _ydtQuestionModel.AnswerTrue.intValue) {
  1051. switch (opt / 10000) {
  1052. case 1:
  1053. _btn02.imgN = @"question_error.png";
  1054. break;
  1055. case 2:
  1056. _btn03.imgN = @"question_error.png";
  1057. break;
  1058. case 3:
  1059. _btn04.imgN = @"question_error.png";
  1060. break;
  1061. case 4:
  1062. _btn05.imgN = @"question_error.png";
  1063. break;
  1064. default:
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. -(void)multiOptsYes:(UIButton*)sender
  1072. {
  1073. NSInteger answ = 0;
  1074. 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"]);
  1075. NSMutableString *str = [NSMutableString string];
  1076. for (int i=0; i<4; i++)
  1077. {
  1078. UIButton* btn = optBtns[i];
  1079. if (btn.selected) {
  1080. [str appendString:arr[i]];
  1081. answ += [arr[i] integerValue];
  1082. }
  1083. }
  1084. if ([self.delegate2 respondsToSelector:@selector(didChooseOption:isRight:)]) {
  1085. [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))];
  1086. }
  1087. [self choose:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? str.integerValue : ([defUser.car_type isEqualToString:@"2"]? answ : str.integerValue)];
  1088. }
  1089. /**
  1090. 使用方法:首先是setQuestion。然后是setAnswer
  1091. 0要恢复按钮点击。
  1092. 16-128要调用choose,表示做过了。
  1093. 这里也要判断一下。是单选还是多选。
  1094. */
  1095. -(void)setAnswer:(NSInteger)answer
  1096. {
  1097. if (0 == answer)
  1098. {
  1099. _btn02.enabled = YES;
  1100. _btn03.enabled = YES;
  1101. _btn04.enabled = YES;
  1102. _btn05.enabled = YES;
  1103. _btnYes.enabled = NO;
  1104. [_btnYes setBackgroundColor:KlineColor];
  1105. return;
  1106. }
  1107. [self choose:answer];
  1108. return;
  1109. }
  1110. #pragma mark -
  1111. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1112. {
  1113. return _comments.count > cellCntMax ? cellCntMax : _comments.count;
  1114. }
  1115. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  1116. {
  1117. NSDictionary *dic = _comments[indexPath.row];
  1118. return 110 + [dic[@"QC_DESC"] heightForWid:(kSize.width - 80) Font:15];
  1119. }
  1120. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1121. {
  1122. CommentCell* cell = [CommentCell cellForTableView:tableView Style:CommentCellStyleQuestion];
  1123. [cell setCommentDic:_comments[indexPath.row]];
  1124. return cell;
  1125. }
  1126. - (UIImage*)videoImageWithvideoURL:(NSURL *)videoURL {
  1127. NSString *cacheKeyStr = [[YYWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:videoURL.absoluteString]];
  1128. UIImage *memoryImage = [[YYImageCache sharedCache] getImageForKey:cacheKeyStr];
  1129. if (memoryImage) {
  1130. return memoryImage;
  1131. } else {
  1132. 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)];
  1133. dispatch_async(dispatch_get_main_queue(), ^{
  1134. YYImageCache * cache = [YYImageCache sharedCache];
  1135. [cache setImage:thumbnailImage forKey:videoURL.absoluteString];
  1136. });
  1137. return thumbnailImage;
  1138. }
  1139. }
  1140. // 获取视频第一帧
  1141. - (UIImage*)firstFrameWithVideoURL:(NSURL*)url size:(CGSize)size {
  1142. NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
  1143. AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];
  1144. AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
  1145. generator.appliesPreferredTrackTransform = YES;
  1146. generator.maximumSize = CGSizeMake(size.width, size.height);
  1147. NSError*error =nil;
  1148. CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(0, 10) actualTime:NULL error:&error];
  1149. {
  1150. return [UIImage imageWithCGImage:img];
  1151. }
  1152. return nil;
  1153. }
  1154. #pragma mark - <QMUIImagePreviewViewDelegate>
  1155. - (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
  1156. return 1;
  1157. }
  1158. - (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
  1159. zoomImageView.reusedIdentifier = @(index);
  1160. // 模拟异步加载的情况
  1161. if (index == 2) {
  1162. [zoomImageView showLoading];
  1163. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1164. if ([zoomImageView.reusedIdentifier isEqual:@(index)]) {
  1165. [zoomImageView hideEmptyView];
  1166. zoomImageView.image = _mediaImg.image;
  1167. zoomImageView.contentMode = UIViewContentModeScaleAspectFill;
  1168. zoomImageView.maximumZoomScale = 3.f;
  1169. }
  1170. });
  1171. } else {
  1172. zoomImageView.image = _mediaImg.image;
  1173. }
  1174. }
  1175. - (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
  1176. return QMUIImagePreviewMediaTypeImage;
  1177. }
  1178. #pragma mark - <QMUIZoomImageViewDelegate>
  1179. - (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
  1180. // 退出图片预览
  1181. [RQControllerHelper.currentViewController dismissViewControllerAnimated:YES completion:^{
  1182. }];
  1183. }
  1184. #pragma mark - LazyLoad
  1185. - (UIImageView *)containerView {
  1186. if (!_containerView) {
  1187. _containerView = [[UIImageView alloc] qmui_initWithSize:CGSizeMake(RQ_SCREEN_WIDTH - 20, (RQ_SCREEN_WIDTH - 20) / 2.f)];
  1188. _containerView.backgroundColor = UIColor.blackColor;
  1189. UILabel *loadingLabel = [[UILabel alloc] qmui_initWithFont:RQRegularFont(25) textColor:RQ_MAIN_TEXT_COLOR_WHITE];
  1190. loadingLabel.text = @"画面加载中...";
  1191. [_containerView addSubview:loadingLabel];
  1192. [loadingLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  1193. make.center.mas_equalTo(_containerView);
  1194. }];
  1195. }
  1196. return _containerView;
  1197. }
  1198. - (void)setIndex:(NSInteger)index {
  1199. _index = index;
  1200. }
  1201. - (QMUIImagePreviewViewController *)imagePreviewViewController {
  1202. @weakify(self)
  1203. if (!_imagePreviewViewController) {
  1204. _imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
  1205. _imagePreviewViewController.presentingStyle = QMUIImagePreviewViewControllerTransitioningStyleZoom;// 将 present 动画改为 zoom,也即从某个位置放大到屏幕中央。默认样式为 fade。
  1206. _imagePreviewViewController.imagePreviewView.delegate = self;// 将内部的图片查看器 delegate 指向当前 viewController,以获取要查看的图片数据
  1207. // 当需要在退出大图预览时做一些事情的时候,可配合 UIViewController (QMUI) 的 qmui_visibleStateDidChangeBlock 来实现。
  1208. _imagePreviewViewController.qmui_visibleStateDidChangeBlock = ^(QMUIImagePreviewViewController *viewController, QMUIViewControllerVisibleState visibleState) {
  1209. if (visibleState == QMUIViewControllerWillDisappear) {
  1210. // NSInteger exitAtIndex = viewController.imagePreviewView.currentImageIndex;
  1211. }
  1212. };
  1213. self.imagePreviewViewController.sourceImageView = ^UIView *{
  1214. @strongify(self)
  1215. return self.mediaImg;
  1216. };
  1217. }
  1218. return _imagePreviewViewController;
  1219. }
  1220. @end