MyStyleVideoCell.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // MyStyleVideoCell.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/11.
  6. //
  7. #import "MyStyleVideoCell.h"
  8. #import "MyStyleVideoView.h"
  9. #import "MyStyleVideoChooseView.h"
  10. @interface MyStyleVideoCell ()
  11. @property (weak, nonatomic) IBOutlet UIView *videoContainer;
  12. @property (nonatomic, copy) NSMutableArray *videoArray;
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *containerHeight;
  14. @property (nonatomic, copy) StyleVideoCellAction callback;
  15. @end
  16. @implementation MyStyleVideoCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. }
  22. - (void)opreationCallback:(StyleVideoCellAction)callback {
  23. if (callback) {
  24. self.callback = callback;
  25. }
  26. }
  27. - (void)configWithSource:(NSMutableArray *)videoArray {
  28. [self.videoContainer removeAllSubViews];
  29. self.videoArray = videoArray;
  30. CGFloat viewWidth = (kScreenWidth - 14 * 2) / 2.0f;
  31. CGFloat height = 128.0f;
  32. CGFloat xPosition = 0.0f;
  33. CGFloat yPosition = 0.0f;
  34. for (NSInteger i = 0; i < videoArray.count; i++) {
  35. StyleVideoModel *model = self.videoArray[i];
  36. if (i % 2 == 0 && i != 0) {
  37. yPosition += height;
  38. xPosition = 0.0f;
  39. }
  40. MyStyleVideoView *videoView = [MyStyleVideoView shareInstance];
  41. videoView.frame = CGRectMake(xPosition, yPosition, viewWidth, height);
  42. videoView.tag = i + 1000;
  43. [self.videoContainer addSubview:videoView];
  44. [videoView configWithSource:model];
  45. MJWeakSelf;
  46. [videoView videoOperationAcion:^(STYLEVIDEO type, MyStyleVideoView * _Nonnull videoView) {
  47. [weakSelf previewVideoAction:type inView:videoView];
  48. }];
  49. xPosition += viewWidth;
  50. }
  51. if (videoArray.count < 5) {
  52. if (videoArray.count % 2 == 0 && videoArray.count != 0) {
  53. yPosition += height;
  54. xPosition = 0.0f;
  55. }
  56. MyStyleVideoChooseView *view = [[MyStyleVideoChooseView alloc] initWithFrame:CGRectMake(xPosition, yPosition, viewWidth, height)];
  57. MJWeakSelf;
  58. [view chooseCallback:^{
  59. [weakSelf chooseVideo];
  60. }];
  61. [self.videoContainer addSubview:view];
  62. }
  63. self.containerHeight.constant = yPosition + height;
  64. }
  65. - (void)previewVideoAction:(STYLEVIDEO)type inView:(MyStyleVideoView *)displayView {
  66. if (self.callback) {
  67. self.callback(type, displayView);
  68. }
  69. }
  70. - (void)chooseVideo {
  71. if (self.callback) {
  72. self.callback(STYLEVIDEO_CHOOSEFILE, nil);
  73. }
  74. }
  75. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  76. [super setSelected:selected animated:animated];
  77. // Configure the view for the selected state
  78. }
  79. @end