NYExerciseQuestionCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // NYExerciseQuestionCell.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/10/30.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYExerciseQuestionCell.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. @interface NYExerciseQuestionCell () <QMUIImagePreviewViewDelegate>
  11. @property (nonatomic, readwrite, strong) NYExerciseQuestionItemViewModel *viewModel;
  12. @property (weak, nonatomic) IBOutlet YYLabel *questionLabel;
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelHeight;
  14. @property (nonatomic, readwrite, strong) ZFPlayerController *zfPlayer;
  15. @property (nonatomic, readwrite, strong) QMUIImagePreviewViewController *imagePreviewViewController;
  16. @property (nonatomic, readwrite, strong) UIImage *subImage;
  17. @end
  18. @implementation NYExerciseQuestionCell
  19. #pragma mark - PublicMethods
  20. + (instancetype)cellWithTableView:(UITableView *)tableView {
  21. static NSString *ID = @"NYExerciseQuestionCell";
  22. NYExerciseQuestionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  23. if (!cell) {
  24. cell = [self rq_viewFromXib];
  25. cell.questionLabel.backgroundColor = UIColor.clearColor;
  26. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  27. }
  28. return cell;
  29. }
  30. - (void)dealloc {
  31. }
  32. - (void)bindViewModel:(NYExerciseQuestionItemViewModel *)viewModel {
  33. _viewModel = viewModel;
  34. self.questionLabel.userInteractionEnabled = YES;
  35. RAC(self.questionLabel, attributedText) = [[RACObserve(viewModel, qusetionString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  36. RAC(self.labelHeight, constant) = [[RACObserve(viewModel, labelHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread];
  37. }
  38. #pragma mark - SystemMethods
  39. - (void)awakeFromNib {
  40. [super awakeFromNib];
  41. // Initialization code
  42. }
  43. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  44. [super setSelected:selected animated:animated];
  45. // Configure the view for the selected state
  46. }
  47. #pragma mark - LazyLoad
  48. - (QMUIImagePreviewViewController *)imagePreviewViewController {
  49. @weakify(self)
  50. if (!_imagePreviewViewController) {
  51. _imagePreviewViewController = [[QMUIImagePreviewViewController alloc] init];
  52. _imagePreviewViewController.presentingStyle = QMUIImagePreviewViewControllerTransitioningStyleZoom;// 将 present 动画改为 zoom,也即从某个位置放大到屏幕中央。默认样式为 fade。
  53. _imagePreviewViewController.imagePreviewView.delegate = self;// 将内部的图片查看器 delegate 指向当前 viewController,以获取要查看的图片数据
  54. // 当需要在退出大图预览时做一些事情的时候,可配合 UIViewController (QMUI) 的 qmui_visibleStateDidChangeBlock 来实现。
  55. _imagePreviewViewController.qmui_visibleStateDidChangeBlock = ^(QMUIImagePreviewViewController *viewController, QMUIViewControllerVisibleState visibleState) {
  56. if (visibleState == QMUIViewControllerWillDisappear) {
  57. RQ_Exercise_Module.isShow_CatalogueView = NO;
  58. // NSInteger exitAtIndex = viewController.imagePreviewView.currentImageIndex;
  59. }
  60. };
  61. }
  62. return _imagePreviewViewController;
  63. }
  64. #pragma mark - <QMUIImagePreviewViewDelegate>
  65. - (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView {
  66. return 1;
  67. }
  68. - (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index {
  69. @weakify(self)
  70. zoomImageView.reusedIdentifier = @(index);
  71. // 模拟异步加载的情况
  72. if (index == 2) {
  73. [zoomImageView showLoading];
  74. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  75. @strongify(self)
  76. if ([zoomImageView.reusedIdentifier isEqual:@(index)]) {
  77. [zoomImageView hideEmptyView];
  78. zoomImageView.image = self.subImage;
  79. zoomImageView.contentMode = UIViewContentModeScaleAspectFill;
  80. zoomImageView.maximumZoomScale = 3.f;
  81. }
  82. });
  83. } else {
  84. zoomImageView.image = self.subImage;
  85. }
  86. }
  87. - (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index {
  88. return QMUIImagePreviewMediaTypeImage;
  89. }
  90. #pragma mark - <QMUIZoomImageViewDelegate>
  91. - (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location {
  92. // 退出图片预览
  93. [RQControllerHelper.currentViewController dismissViewControllerAnimated:YES completion:nil];
  94. }
  95. @end