JXSelectCoverVC.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // JXSelectCoverVC.m
  3. // shiku_im
  4. //
  5. // Created by IMAC on 2019/7/31.
  6. // Copyright © 2019 Reese. All rights reserved.
  7. //
  8. #import "JXSelectCoverVC.h"
  9. #import "RITLPhotosViewController.h"
  10. #import "RITLPhotosDataManager.h"
  11. #define imgVWidth (JX_SCREEN_WIDTH - 25) / 4
  12. #define imgVHeight 131
  13. @interface JXSelectCoverVC ()<RITLPhotosViewControllerDelegate>
  14. @property (nonatomic,strong)NSMutableArray *imageArray;
  15. @property (nonatomic,strong)NSString *video;
  16. @end
  17. @implementation JXSelectCoverVC
  18. - (instancetype)initWithVideo:(NSString *)video{
  19. if (self = [super init]) {
  20. self.video = video;
  21. }
  22. return self;
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.isGotoBack = YES;
  27. self.heightHeader = JX_SCREEN_TOP;
  28. self.heightFooter = 0;
  29. [self createHeadAndFoot];
  30. self.headerTitle.text = Localized(@"JX_ChooseVideoCover");
  31. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(self_width-7-65, JX_SCREEN_TOP - 38, 65, 30)];
  32. if (THESIMPLESTYLE) {
  33. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  34. }else{
  35. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  36. }
  37. [btn setTitle:Localized(@"ALBUM") forState:UIControlStateNormal];
  38. btn.backgroundColor = [UIColor clearColor];
  39. [btn addTarget:self action:@selector(gotoImage) forControlEvents:UIControlEventTouchUpInside];
  40. [self.tableHeader addSubview:btn];
  41. [self.tableBody setScrollEnabled:YES];
  42. self.tableBody.backgroundColor = [UIColor whiteColor];
  43. self.imageArray = [NSMutableArray array];
  44. [self createImages];
  45. }
  46. - (void) createImages {
  47. [_wait start:Localized(@"JX_Loading")];
  48. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  49. double integer = [FileInfo getVideoTimeFromVideo:self.video];
  50. NSInteger num = 0;
  51. double interval;
  52. if (integer < 16) {
  53. interval = integer/16;
  54. num = 16;
  55. }else if (integer >= 16 && integer <= 32){
  56. interval = 1;
  57. num = ceil(integer);
  58. }else{
  59. interval = integer/32;
  60. num = 32;
  61. }
  62. for (int i = 0; i< num; i++) {
  63. UIImage *image = [FileInfo getImagesFromVideo:self.video withTimeInterval:interval*(i+1)];
  64. if (image) {
  65. [_imageArray addObject:image];
  66. }
  67. }
  68. dispatch_async(dispatch_get_main_queue(), ^{
  69. for (int i = 0; i < _imageArray.count; i++) {
  70. if (i <= 3) {
  71. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*i, 0, imgVWidth , imgVHeight) index:i];
  72. }else if (i > 3 && i <= 7 ) {
  73. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-4), (imgVHeight + 5) * 1, imgVWidth, imgVHeight) index:i];
  74. }else if(i > 7 && i <= 11){
  75. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-8), (imgVHeight + 5) * 2, imgVWidth, imgVHeight) index:i];
  76. }else if(i > 11 && i <= 15){
  77. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-12), (imgVHeight + 5) * 3, imgVWidth, imgVHeight) index:i];
  78. }else if(i > 15 && i <= 19){
  79. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-16), (imgVHeight + 5) * 4, imgVWidth, imgVHeight) index:i];
  80. }else if(i > 19 && i <= 23){
  81. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-20), (imgVHeight + 5) * 5, imgVWidth, imgVHeight) index:i];
  82. }else if (i > 23 && i <= 27){
  83. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-24), (imgVHeight + 5) * 6, imgVWidth, imgVHeight) index:i];
  84. }else{
  85. [self createImageViewWithImage:_imageArray[i] frame:CGRectMake(5+(imgVWidth + 5)*(i-28), (imgVHeight + 5) * 7, imgVWidth, imgVHeight) index:i];
  86. }
  87. }
  88. int row = ceilf(_imageArray.count / 4.0);
  89. self.tableBody.contentSize = CGSizeMake(JX_SCREEN_WIDTH, (imgVHeight + 5) * row - 5);
  90. [_wait stop];
  91. });
  92. });
  93. }
  94. - (void)gotoImage{
  95. RITLPhotosViewController *photoController = RITLPhotosViewController.photosViewController;
  96. photoController.configuration.maxCount = 1;//最大的选择数目
  97. photoController.configuration.containVideo = NO;
  98. photoController.configuration.containImage = YES;
  99. photoController.photo_delegate = self;
  100. CGSize assetSize = CGSizeMake(320, 320);
  101. photoController.thumbnailSize = assetSize;
  102. [self presentViewController:photoController animated:true completion:^{}];
  103. }
  104. - (void)photosViewController:(UIViewController *)viewController images:(NSArray <UIImage *> *)images infos:(NSArray <NSDictionary *> *)infos{
  105. UIImage *img = images[0];
  106. if ([self.delegate respondsToSelector:@selector(touchAtlasButtonReturnCover:)]) {
  107. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  108. [self.delegate touchAtlasButtonReturnCover:img];
  109. });
  110. }
  111. }
  112. - (void)photosViewController:(UIViewController *)viewController thumbnailImages:(NSArray <UIImage *> *)thumbnailImages infos:(NSArray <NSDictionary *> *)infos{
  113. UIImage *img = thumbnailImages[0];
  114. if ([self.delegate respondsToSelector:@selector(touchAtlasButtonReturnCover:)]) {
  115. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  116. [self.delegate touchAtlasButtonReturnCover:img];
  117. });
  118. }
  119. [g_navigation dismissViewController:self animated:YES];
  120. }
  121. - (void)didImageView:(UIGestureRecognizer *)sender{
  122. if ([self.delegate respondsToSelector:@selector(selectImage: toView:)]) {
  123. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  124. [self.delegate selectImage:((UIImageView *)sender.view).image toView:self];
  125. // });
  126. }
  127. [g_navigation dismissViewController:self animated:YES];
  128. }
  129. - (void)createImageViewWithImage:(UIImage *)img frame:(CGRect )frame index:(NSInteger)index{
  130. UIImageView *imgV = [[UIImageView alloc] initWithImage:img];
  131. imgV.frame = frame;
  132. imgV.tag = index;
  133. imgV.userInteractionEnabled = YES;
  134. UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didImageView:)];
  135. [imgV addGestureRecognizer:ges];
  136. [self.tableBody addSubview:imgV];
  137. }
  138. @end