// // NYExerciseQuestionCell.m // jiaPei // // Created by Ning.ge on 2024/10/30. // Copyright © 2024 JCZ. All rights reserved. // #import "NYExerciseQuestionCell.h" #import @interface NYExerciseQuestionCell () @property (nonatomic, readwrite, strong) NYExerciseQuestionItemViewModel *viewModel; @property (weak, nonatomic) IBOutlet YYLabel *questionLabel; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelHeight; @property (nonatomic, readwrite, strong) ZFPlayerController *zfPlayer; @property (nonatomic, readwrite, strong) QMUIImagePreviewViewController *imagePreviewViewController; @property (nonatomic, readwrite, strong) UIImage *subImage; @end @implementation NYExerciseQuestionCell #pragma mark - PublicMethods + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"NYExerciseQuestionCell"; NYExerciseQuestionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [self rq_viewFromXib]; cell.questionLabel.backgroundColor = UIColor.clearColor; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (void)dealloc { } - (void)bindViewModel:(NYExerciseQuestionItemViewModel *)viewModel { _viewModel = viewModel; self.questionLabel.userInteractionEnabled = YES; RAC(self.questionLabel, attributedText) = [[RACObserve(viewModel, qusetionString) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; RAC(self.labelHeight, constant) = [[RACObserve(viewModel, labelHeight) takeUntil:self.rac_prepareForReuseSignal] deliverOnMainThread]; } #pragma mark - SystemMethods - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } #pragma mark - LazyLoad - (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) { RQ_Exercise_Module.isShow_CatalogueView = NO; // NSInteger exitAtIndex = viewController.imagePreviewView.currentImageIndex; } }; } return _imagePreviewViewController; } #pragma mark - - (NSUInteger)numberOfImagesInImagePreviewView:(QMUIImagePreviewView *)imagePreviewView { return 1; } - (void)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView renderZoomImageView:(QMUIZoomImageView *)zoomImageView atIndex:(NSUInteger)index { @weakify(self) 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(), ^{ @strongify(self) if ([zoomImageView.reusedIdentifier isEqual:@(index)]) { [zoomImageView hideEmptyView]; zoomImageView.image = self.subImage; zoomImageView.contentMode = UIViewContentModeScaleAspectFill; zoomImageView.maximumZoomScale = 3.f; } }); } else { zoomImageView.image = self.subImage; } } - (QMUIImagePreviewMediaType)imagePreviewView:(QMUIImagePreviewView *)imagePreviewView assetTypeAtIndex:(NSUInteger)index { return QMUIImagePreviewMediaTypeImage; } #pragma mark - - (void)singleTouchInZoomingImageView:(QMUIZoomImageView *)zoomImageView location:(CGPoint)location { // 退出图片预览 [RQControllerHelper.currentViewController dismissViewControllerAnimated:YES completion:nil]; } @end