PCSPreviewViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. //
  2. // PCSPreviewViewController.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by lr on 2023/3/11.
  6. //
  7. #import "PCSPreviewViewController.h"
  8. #import <Masonry/Masonry.h>
  9. #import "QuitMultipleModeAlertViewController.h"
  10. #import "UIImage+name.h"
  11. #import <AVFoundation/AVFoundation.h>
  12. #import <AVKit/AVKit.h>
  13. @interface PCSPreCollectionCell : UICollectionViewCell
  14. @property (nonatomic) LenzResourceItemModel *model;
  15. @property (nonatomic) UIImageView *imageView;
  16. @property (nonatomic) UIImageView *videoImageView;
  17. @property (nonatomic) AVPlayerViewController *player;
  18. @property (nonatomic) BOOL isPlayer;
  19. @end
  20. @implementation PCSPreCollectionCell
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. if (self = [super initWithFrame:frame]) {
  23. self.contentView.backgroundColor = [UIColor clearColor];
  24. [self.contentView addSubview:self.imageView];
  25. [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.edges.mas_offset(0);
  27. }];
  28. [self.contentView addSubview:self.videoImageView];
  29. [self.videoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.center.mas_equalTo(self.contentView);
  31. make.width.height.mas_offset(48);
  32. }];
  33. // player.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
  34. // player.view.hidden = YES;
  35. [self.contentView addSubview:self.player.view];
  36. }
  37. return self;
  38. }
  39. - (void)setModel:(LenzResourceItemModel *)model {
  40. _model = model;
  41. self.imageView.image = model.image;
  42. if (model.mode == SDK_CAPTURE_MODE_MOVIE) {
  43. self.videoImageView.hidden = NO;
  44. } else {
  45. self.videoImageView.hidden = YES;
  46. }
  47. }
  48. - (void)setIsPlayer:(BOOL)isPlayer {
  49. if (isPlayer) {
  50. AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:_model.path]];
  51. self.player.player = player;
  52. [self.player.player play];
  53. self.player.view.hidden = NO;
  54. } else {
  55. [self.player.player pause];
  56. self.player.view.hidden = YES;
  57. }
  58. }
  59. - (void)layoutSubviews {
  60. [super layoutSubviews];
  61. self.player.view.frame = self.contentView.bounds;
  62. }
  63. - (UIImageView *)imageView {
  64. if (!_imageView) {
  65. _imageView = [[UIImageView alloc]init];
  66. _imageView.layer.cornerRadius = 8;
  67. _imageView.layer.masksToBounds = YES;
  68. _imageView.backgroundColor = [UIColor blackColor];
  69. _imageView.contentMode = UIViewContentModeScaleAspectFit;
  70. }
  71. return _imageView;
  72. }
  73. - (UIImageView *)videoImageView {
  74. if (!_videoImageView) {
  75. _videoImageView = [[UIImageView alloc]init];
  76. _videoImageView.image = [UIImage loadNamed:@"icon_video"];
  77. _videoImageView.hidden = YES;
  78. }
  79. return _videoImageView;
  80. }
  81. - (AVPlayerViewController *)player {
  82. if (!_player) {
  83. _player = [[AVPlayerViewController alloc]init];
  84. _player.view.hidden = YES;
  85. _player.videoGravity = AVLayerVideoGravityResizeAspect;
  86. }
  87. return _player;
  88. }
  89. @end
  90. @interface PCSPreviewViewController ()<UIScrollViewDelegate, AVPlayerViewControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
  91. @property (nonatomic) UILabel *countLabel;
  92. @property (nonatomic) UIView *modeView;
  93. @property (nonatomic) UIScrollView *scrollView;
  94. @property (nonatomic) UILabel *curentLabel;
  95. @property (nonatomic) UIView *bottomView;
  96. @property (nonatomic) UIButton *backButton;
  97. @property (nonatomic) UILabel *backLabel;
  98. @property (nonatomic) UIButton *deleteButton;
  99. @property (nonatomic) UILabel *deleteLabel;
  100. @property (nonatomic) UIImageView *lineImageView;
  101. @property (nonatomic) NSInteger currentIndex;
  102. @property (nonatomic) UIImageView *videoImageView;
  103. @property (nonatomic) AVPlayerViewController *lastPlayer;
  104. //@property (nonatomic) NSInteger currentModeDataIndex;
  105. @property (nonatomic) NSMutableArray <AVPlayerViewController *> *allPlayer;
  106. @property (nonatomic) UICollectionView* collectionView;
  107. @property (nonatomic) NSIndexPath *playerIndexPath;
  108. @property (nonatomic) NSIndexPath *currentIndexPath;
  109. @end
  110. @implementation PCSPreviewViewController
  111. - (void)dealloc {
  112. }
  113. - (void)viewDidLoad {
  114. [super viewDidLoad];
  115. self.allPlayer = [NSMutableArray array];
  116. self.view.backgroundColor = [UIColor colorWithRed:60/255.0 green:58/255.0 blue:61/255.0 alpha:1];
  117. [self.view addSubview:self.countLabel];
  118. CGFloat top = UIApplication.sharedApplication.delegate.window.safeAreaInsets.top;
  119. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.top.mas_offset(top + 20);
  121. make.right.mas_offset(-20);
  122. make.height.mas_offset(44);
  123. }];
  124. [self.view addSubview:self.modeView];
  125. [self.modeView mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.mas_offset(0);
  127. make.top.mas_equalTo(self.countLabel);
  128. make.height.mas_equalTo(self.countLabel);
  129. make.right.mas_equalTo(self.countLabel.mas_left).mas_offset(-10);
  130. }];
  131. [self setupModeView];
  132. [self.view addSubview:self.bottomView];
  133. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.right.bottom.mas_offset(0);
  135. make.height.mas_offset(150);
  136. }];
  137. [self.bottomView addSubview:self.backLabel];
  138. [self.backLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.bottom.mas_offset(-30);
  140. make.centerX.mas_equalTo(self.bottomView).mas_offset(-60);
  141. }];
  142. [self.bottomView addSubview:self.backButton];
  143. [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.bottom.mas_equalTo(self.backLabel.mas_top).mas_offset(-20);
  145. make.centerX.mas_equalTo(self.backLabel);
  146. make.width.height.mas_offset(60);
  147. }];
  148. [self.bottomView addSubview:self.deleteLabel];
  149. [self.deleteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.bottom.mas_offset(-30);
  151. make.centerX.mas_equalTo(self.bottomView).mas_offset(60);
  152. }];
  153. [self.bottomView addSubview:self.deleteButton];
  154. [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.bottom.mas_equalTo(self.deleteLabel.mas_top).mas_offset(-20);
  156. make.centerX.mas_equalTo(self.deleteLabel);
  157. make.width.height.mas_offset(60);
  158. }];
  159. UICollectionViewFlowLayout* layout = [[UICollectionViewFlowLayout alloc]init];
  160. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  161. layout.minimumLineSpacing = 0;
  162. layout.minimumInteritemSpacing = 0;
  163. layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, [UIScreen mainScreen].bounds.size.height - top - 224);
  164. self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
  165. self.collectionView.delegate = self;
  166. self.collectionView.dataSource = self;
  167. self.collectionView.pagingEnabled = YES;
  168. self.collectionView.backgroundColor = [UIColor clearColor];
  169. self.collectionView.hidden = YES;
  170. // 注册item类型
  171. [self.collectionView registerClass:[PCSPreCollectionCell class] forCellWithReuseIdentifier:@"PCSPreCollectionCell"];
  172. [self.view addSubview:self.collectionView];
  173. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.left.mas_offset(20);
  175. make.right.mas_offset(-20);
  176. make.top.mas_equalTo(self.countLabel.mas_bottom).mas_offset(10);
  177. make.bottom.mas_equalTo(self.bottomView.mas_top);
  178. }];
  179. self.currentIndexPath = nil;
  180. if (self.model.continousArray.count > 0 && self.selectIndex == SDK_CAPTURE_MODE_CONTINUOUS) {
  181. self.currentIndex = 1;
  182. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.continousArray.count - 1 inSection:0];
  183. }
  184. if (self.model.movieArray.count > 0 && self.selectIndex == SDK_CAPTURE_MODE_MOVIE) {
  185. self.currentIndex = 2;
  186. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.movieArray.count - 1 inSection:1];
  187. }
  188. if (self.model.panoramArray.count > 0 && self.selectIndex == SDK_CAPTURE_MODE_PANORAMA) {
  189. self.currentIndex = 3;
  190. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.panoramArray.count - 1 inSection:2];
  191. }
  192. if (self.model.aiPanoramArray.count > 0 && self.selectIndex == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
  193. self.currentIndex = 4;
  194. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.aiPanoramArray.count - 1 inSection:3];
  195. }
  196. if(!self.currentIndexPath) {
  197. if (self.model.aiPanoramArray.count > 0) {
  198. self.currentIndex = 4;
  199. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.aiPanoramArray.count - 1 inSection:3];
  200. } else if (self.model.panoramArray.count > 0) {
  201. self.currentIndex = 3;
  202. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.panoramArray.count - 1 inSection:2];
  203. } else if (self.model.movieArray.count > 0) {
  204. self.currentIndex = 2;
  205. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.movieArray.count - 1 inSection:1];
  206. } else {
  207. self.currentIndex = 1;
  208. self.currentIndexPath = [NSIndexPath indexPathForItem:self.model.continousArray.count - 1 inSection:0];
  209. }
  210. }
  211. [self changeLabelStatusWith:self.currentIndex];
  212. [self updateCountLabelWith:self.currentIndexPath];
  213. [self.view addSubview:self.curentLabel];
  214. [self.curentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  215. make.centerX.mas_equalTo(self.view);
  216. make.width.mas_offset(100);
  217. make.height.mas_offset(32);
  218. make.bottom.mas_equalTo(self.collectionView).mas_offset(16);
  219. }];
  220. }
  221. - (void)viewDidAppear:(BOOL)animated {
  222. [super viewDidAppear:animated];
  223. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  224. self.collectionView.hidden = NO;
  225. UICollectionViewLayoutAttributes*attributes = [self.collectionView layoutAttributesForItemAtIndexPath:self.currentIndexPath];
  226. CGRect rect = attributes.frame;
  227. [self.collectionView setContentOffset:CGPointMake(rect.origin.x, rect.origin.y ) animated:NO];
  228. });
  229. }
  230. - (UIImageView *)lineImageView {
  231. if (!_lineImageView) {
  232. _lineImageView = [[UIImageView alloc]init];
  233. _lineImageView.image = [UIImage loadNamed:@"icon_preview_line"];
  234. }
  235. return _lineImageView;
  236. }
  237. - (void)updateCountLabelWith:(NSIndexPath *)indexPath {
  238. if (!indexPath) {
  239. return;
  240. }
  241. if (indexPath.section == 0) {
  242. self.curentLabel.text = [NSString stringWithFormat:@"第%ld/%ld张", self.currentIndexPath.row + 1, self.model.continousArray.count];
  243. } else if (indexPath.section == 1) {
  244. self.curentLabel.text = [NSString stringWithFormat:@"第%ld/%ld条", self.currentIndexPath.row + 1, self.model.movieArray.count];
  245. } else if (indexPath.section == 2) {
  246. self.curentLabel.text = [NSString stringWithFormat:@"第%ld/%ld张", self.currentIndexPath.row + 1, self.model.panoramArray.count];
  247. } else {
  248. self.curentLabel.text = [NSString stringWithFormat:@"第%ld/%ld张", self.currentIndexPath.row + 1, self.model.aiPanoramArray.count];
  249. }
  250. }
  251. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  252. return 4;
  253. }
  254. //返回每个分区的item个数
  255. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  256. if (section == 0) {
  257. return self.model.continousArray.count;
  258. } else if (section == 1) {
  259. return self.model.movieArray.count;
  260. } else if (section == 2) {
  261. return self.model.panoramArray.count;
  262. } else {
  263. return self.model.aiPanoramArray.count;
  264. }
  265. }
  266. //返回每个item
  267. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  268. PCSPreCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PCSPreCollectionCell" forIndexPath:indexPath];
  269. cell.isPlayer = NO;
  270. if (indexPath.section == 0) {
  271. if (self.model.continousArray.count > indexPath.row) {
  272. LenzResourceItemModel *model = self.model.continousArray[indexPath.row];
  273. cell.model = model;
  274. }
  275. } else if (indexPath.section == 1) {
  276. if (self.model.movieArray.count > indexPath.row) {
  277. LenzResourceItemModel *model = self.model.movieArray[indexPath.row];
  278. cell.model = model;
  279. cell.isPlayer = indexPath == self.playerIndexPath;
  280. }
  281. } else if (indexPath.section == 2) {
  282. if (self.model.panoramArray.count > indexPath.row) {
  283. LenzResourceItemModel *model = self.model.panoramArray[indexPath.row];
  284. cell.model = model;
  285. }
  286. } else if (indexPath.section == 3) {
  287. if (self.model.aiPanoramArray.count > indexPath.row) {
  288. LenzResourceItemModel *model = self.model.aiPanoramArray[indexPath.row];
  289. cell.model = model;
  290. }
  291. }
  292. return cell;
  293. }
  294. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  295. if (indexPath.section == 1) {
  296. self.playerIndexPath = indexPath;
  297. [self.collectionView reloadData];
  298. }
  299. }
  300. // 监听UIScrollView的滑动停止
  301. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  302. self.playerIndexPath = nil;
  303. NSArray *indexPaths = [self.collectionView indexPathsForVisibleItems];
  304. NSIndexPath *currentIndexPath = indexPaths.firstObject;
  305. self.currentIndexPath = currentIndexPath;
  306. [self changeLabelStatusWith:currentIndexPath.section + 1];
  307. [self updateCountLabelWith:currentIndexPath];
  308. }
  309. - (void)updateCurrentIndexPath {
  310. NSArray *indexPaths = [self.collectionView indexPathsForVisibleItems];
  311. NSIndexPath *currentIndexPath = indexPaths.firstObject;
  312. self.currentIndexPath = currentIndexPath;
  313. [self changeLabelStatusWith:currentIndexPath.section + 1];
  314. [self updateCountLabelWith:currentIndexPath];
  315. }
  316. - (void)updateViewWhenDelete {
  317. self.playerIndexPath = nil;
  318. NSArray *indexPaths = [self.collectionView indexPathsForVisibleItems];
  319. NSIndexPath *currentIndexPath = indexPaths.firstObject;
  320. self.currentIndexPath = currentIndexPath;
  321. [self changeLabelStatusWith:currentIndexPath.section + 1];
  322. [self updateCountLabelWith:currentIndexPath];
  323. }
  324. - (void)setupModeView {
  325. [self.modeView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  326. CGFloat margin = [UIScreen mainScreen].bounds.size.width == 375 ? 20 : 30;
  327. UIView *lastView = nil;
  328. NSInteger count = 0;
  329. self.currentIndex = 0;
  330. if (self.model.continousArray.count) {
  331. count += self.model.continousArray.count;
  332. self.currentIndex = 1;
  333. UILabel *label = [[UILabel alloc]init];
  334. label.text = @"连拍";
  335. label.tag = 1;
  336. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeAction:)];
  337. [label addGestureRecognizer:tap];
  338. label.userInteractionEnabled = YES;
  339. label.textColor = [UIColor whiteColor];
  340. [self.modeView addSubview:label];
  341. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  342. make.left.mas_offset(20);
  343. make.centerY.mas_equalTo(self.countLabel);
  344. }];
  345. lastView = label;
  346. }
  347. if (self.model.movieArray.count) {
  348. count += self.model.movieArray.count;
  349. if (self.currentIndex == 0) {
  350. self.currentIndex = 2;
  351. }
  352. UILabel *label = [[UILabel alloc]init];
  353. label.text = @"视频";
  354. label.tag = 2;
  355. label.textColor = [UIColor whiteColor];
  356. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeAction:)];
  357. [label addGestureRecognizer:tap];
  358. label.userInteractionEnabled = YES;
  359. [self.modeView addSubview:label];
  360. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  361. if (lastView) {
  362. make.left.mas_equalTo(lastView.mas_right).mas_offset(margin);
  363. } else {
  364. make.left.mas_equalTo(20);
  365. }
  366. make.centerY.mas_equalTo(self.countLabel);
  367. }];
  368. lastView = label;
  369. }
  370. if (self.model.panoramArray.count) {
  371. count += self.model.panoramArray.count;
  372. if (self.currentIndex == 0) {
  373. self.currentIndex = 3;
  374. }
  375. UILabel *label = [[UILabel alloc]init];
  376. label.text = @"全景";
  377. label.tag = 3;
  378. label.textColor = [UIColor whiteColor];
  379. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeAction:)];
  380. [label addGestureRecognizer:tap];
  381. label.userInteractionEnabled = YES;
  382. [self.modeView addSubview:label];
  383. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  384. if (lastView) {
  385. make.left.mas_equalTo(lastView.mas_right).mas_offset(margin);
  386. } else {
  387. make.left.mas_equalTo(20);
  388. }
  389. make.centerY.mas_equalTo(self.countLabel);
  390. }];
  391. lastView = label;
  392. }
  393. if (self.model.aiPanoramArray.count) {
  394. count += self.model.aiPanoramArray.count;
  395. if (self.currentIndex == 0) {
  396. self.currentIndex = 4;
  397. }
  398. UILabel *label = [[UILabel alloc]init];
  399. label.text = @"智能全景";
  400. label.tag = 4;
  401. label.textColor = [UIColor whiteColor];
  402. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeAction:)];
  403. [label addGestureRecognizer:tap];
  404. label.userInteractionEnabled = YES;
  405. [self.modeView addSubview:label];
  406. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  407. if (lastView) {
  408. make.left.mas_equalTo(lastView.mas_right).mas_offset(margin);
  409. } else {
  410. make.left.mas_equalTo(20);
  411. }
  412. make.centerY.mas_equalTo(self.countLabel);
  413. }];
  414. lastView = label;
  415. }
  416. self.countLabel.text = [NSString stringWithFormat:@"共%ld笔数据", count];
  417. [self.modeView addSubview:self.lineImageView];
  418. }
  419. - (void)updateTotal {
  420. NSInteger count = 0;
  421. if (self.model.continousArray.count) {
  422. count += self.model.continousArray.count;
  423. }
  424. if (self.model.movieArray.count) {
  425. count += self.model.movieArray.count;
  426. }
  427. if (self.model.panoramArray.count) {
  428. count += self.model.panoramArray.count;
  429. }
  430. if (self.model.aiPanoramArray.count) {
  431. count += self.model.aiPanoramArray.count;
  432. }
  433. self.countLabel.text = [NSString stringWithFormat:@"共%ld笔数据", count];
  434. }
  435. - (void)changeAction:(UITapGestureRecognizer *)tap {
  436. [self.view layoutIfNeeded];
  437. UILabel *label = (UILabel *)tap.view;
  438. self.currentIndexPath = [NSIndexPath indexPathForItem:0 inSection:label.tag - 1];
  439. UICollectionViewLayoutAttributes*attributes = [self.collectionView layoutAttributesForItemAtIndexPath:self.currentIndexPath];
  440. CGRect rect = attributes.frame;
  441. [self.collectionView setContentOffset:CGPointMake(rect.origin.x, rect.origin.y ) animated:NO];
  442. [self changeLabelStatusWith:label.tag];
  443. [self updateCountLabelWith:self.currentIndexPath];
  444. }
  445. - (void)changeLabelStatusWith:(NSInteger)index {
  446. if(index <=0) {
  447. return;
  448. }
  449. UILabel *label1 = [self.modeView viewWithTag:1];
  450. if (label1) {
  451. label1.textColor = [UIColor whiteColor];
  452. }
  453. UILabel *label2 = [self.modeView viewWithTag:2];
  454. if (label2) {
  455. label2.textColor = [UIColor whiteColor];
  456. }
  457. UILabel *label3 = [self.modeView viewWithTag:3];
  458. if (label3) {
  459. label3.textColor = [UIColor whiteColor];
  460. }
  461. UILabel *label4 = [self.modeView viewWithTag:4];
  462. if (label4) {
  463. label4.textColor = [UIColor whiteColor];
  464. }
  465. UILabel *label = (UILabel *)[self.modeView viewWithTag:index];
  466. if (label) {
  467. label.textColor = [UIColor colorWithRed:231/255.0 green:108/255.0 blue:30/255.0 alpha:1];
  468. [self.lineImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  469. make.top.mas_equalTo(label.mas_bottom);
  470. make.centerX.mas_equalTo(label);
  471. make.width.mas_offset(18);
  472. make.height.mas_offset(9);
  473. }];
  474. }
  475. self.currentIndex = index;
  476. }
  477. - (void)updateScrollWith:(NSInteger)tag {
  478. if (tag > 0) {
  479. NSArray <LenzResourceItemModel *> *source = nil;
  480. if (tag == 1) {
  481. source = self.model.continousArray;
  482. } else if (tag == 2) {
  483. source = self.model.movieArray;
  484. } else if (tag == 3) {
  485. source = self.model.panoramArray;
  486. } else if (tag == 4) {
  487. source = self.model.aiPanoramArray;
  488. }
  489. [self updateScrollViewWith:source];
  490. }
  491. }
  492. - (void)updateScrollViewWith:(NSArray <LenzResourceItemModel *> *)array {
  493. CGFloat width = CGRectGetWidth(self.scrollView.frame);
  494. CGFloat height = CGRectGetHeight(self.scrollView.frame);
  495. [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  496. self.scrollView.pagingEnabled = YES;
  497. self.scrollView.contentSize = CGSizeMake(width * array.count, height);
  498. __block UIImageView *lastImageView = nil;
  499. [array enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  500. UIImageView *imageView = [[UIImageView alloc]init];
  501. imageView.image = obj.image;
  502. imageView.tag = idx;
  503. [self.scrollView addSubview:imageView];
  504. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  505. make.top.mas_offset(0);
  506. make.height.mas_offset(height);
  507. make.width.mas_offset(width);
  508. if (lastImageView) {
  509. make.left.mas_equalTo(lastImageView.mas_right);
  510. } else {
  511. make.left.mas_offset(0);
  512. }
  513. }];
  514. UIImageView *videoImageView = [[UIImageView alloc]init];
  515. videoImageView.image = [UIImage loadNamed:@"icon_video"];
  516. [imageView addSubview:videoImageView];
  517. [videoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  518. make.center.mas_equalTo(imageView);
  519. make.width.height.mas_offset(48);
  520. }];
  521. [self.view setNeedsLayout];
  522. [self.view layoutIfNeeded];
  523. if (obj.mode == SDK_CAPTURE_MODE_MOVIE) {
  524. videoImageView.hidden = NO;
  525. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(videoAction:)];
  526. [imageView addGestureRecognizer:tap];
  527. imageView.userInteractionEnabled = YES;
  528. AVPlayerViewController *player = [[AVPlayerViewController alloc]init];
  529. player.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
  530. player.view.hidden = YES;
  531. [imageView addSubview:player.view];
  532. [self.allPlayer addObject:player];
  533. } else {
  534. videoImageView.hidden = YES;
  535. }
  536. lastImageView = imageView;
  537. }];
  538. self.curentLabel.text = [NSString stringWithFormat:@"第%d/%ld条", 1, array.count];
  539. }
  540. - (void)videoAction:(UITapGestureRecognizer *)tap {
  541. UIImageView *view = (UIImageView *)tap.view;
  542. if (self.model.movieArray.count > view.tag) {
  543. LenzResourceItemModel *model = self.model.movieArray[view.tag];
  544. AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:model.path]];
  545. if (self.lastPlayer) {
  546. [self.lastPlayer.player pause];
  547. self.lastPlayer.player = nil;
  548. self.lastPlayer.view.hidden = YES;
  549. }
  550. AVPlayerViewController *playerVC = self.allPlayer[view.tag];
  551. playerVC.view.hidden = NO;
  552. playerVC.player = player;
  553. [playerVC.player play];
  554. self.lastPlayer = playerVC;
  555. }
  556. }
  557. - (void)backAction {
  558. [self dismissViewControllerAnimated:YES completion:nil];
  559. }
  560. - (void)deleteAction {
  561. NSString *title = @"图片删除后无法恢复,请确认!";
  562. if (self.currentIndex == 2) {
  563. title = @"视频删除后无法恢复,请确认!";
  564. }
  565. [QuitMultipleModeAlertViewController show:self title:@"确认提醒" text:title leftBtnTitle:@"取消" rightBtnTitle:@"确定" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  566. [alertController dismissViewControllerAnimated:YES completion:nil];
  567. } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  568. NSIndexPath *showIndexPath = nil;
  569. if (self.currentIndex == 1) {
  570. if (self.model.continousArray.count > self.currentIndexPath.item) {
  571. [self.model.continousArray removeObjectAtIndex:self.currentIndexPath.item];
  572. }
  573. if (self.model.continousArray.count > 0 ) {
  574. showIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.item - 1 inSection:self.currentIndexPath.section];
  575. }
  576. } else if (self.currentIndex == 2) {
  577. if (self.model.movieArray.count > self.currentIndexPath.item) {
  578. [self.model.movieArray removeObjectAtIndex:self.currentIndexPath.item];
  579. }
  580. if (self.model.movieArray.count > 0 ) {
  581. showIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.item - 1 inSection:self.currentIndexPath.section];
  582. }
  583. } else if (self.currentIndex == 3) {
  584. if (self.model.panoramArray.count > self.currentIndexPath.item) {
  585. [self.model.panoramArray removeObjectAtIndex:self.currentIndexPath.item];
  586. }
  587. if (self.model.panoramArray.count > 0 ) {
  588. showIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.item - 1 inSection:self.currentIndexPath.section];
  589. }
  590. } else if (self.currentIndex == 4) {
  591. if (self.model.aiPanoramArray.count > self.currentIndexPath.item) {
  592. [self.model.aiPanoramArray removeObjectAtIndex:self.currentIndexPath.item];
  593. }
  594. if (self.model.aiPanoramArray.count > 0 ) {
  595. showIndexPath = [NSIndexPath indexPathForRow:self.currentIndexPath.item - 1 inSection:self.currentIndexPath.section];
  596. }
  597. }
  598. if(showIndexPath) {
  599. UICollectionViewLayoutAttributes*attributes = [self.collectionView layoutAttributesForItemAtIndexPath:showIndexPath];
  600. CGRect rect = attributes.frame;
  601. [self.collectionView reloadData];
  602. [self.collectionView setContentOffset:CGPointMake(rect.origin.x, rect.origin.y ) animated:NO];
  603. } else {
  604. [self setupModeView];
  605. [self scrollViewDidEndDecelerating:self.collectionView];
  606. [self.collectionView reloadData];
  607. }
  608. [self.view setNeedsLayout];
  609. [self.view layoutIfNeeded];
  610. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  611. [self updateCurrentIndexPath];
  612. });
  613. [self updateTotal];
  614. [self updateViewWhenDelete];
  615. if (self.dataChangeBlock) {
  616. self.dataChangeBlock();
  617. }
  618. if (self.model.continousArray.count == 0 &&
  619. self.model.movieArray.count == 0 &&
  620. self.model.panoramArray.count == 0 &&
  621. self.model.aiPanoramArray.count == 0) {
  622. self.curentLabel.hidden = YES;
  623. [alertController dismissViewControllerAnimated:YES completion:^{
  624. [self dismissViewControllerAnimated:YES completion:nil];
  625. }];
  626. } else {
  627. self.curentLabel.hidden = NO;
  628. [alertController dismissViewControllerAnimated:YES completion:nil];
  629. }
  630. }];
  631. }
  632. - (UILabel *)countLabel {
  633. if (!_countLabel) {
  634. _countLabel = [[UILabel alloc]init];
  635. _countLabel.font = [UIFont systemFontOfSize:14];
  636. _countLabel.textColor = [UIColor colorWithRed:231/255.0 green:108/255.0 blue:30/255.0 alpha:1];
  637. }
  638. return _countLabel;
  639. }
  640. - (UIView *)bottomView {
  641. if (!_bottomView) {
  642. _bottomView = [[UIView alloc]init];
  643. }
  644. return _bottomView;
  645. }
  646. - (UIView *)modeView {
  647. if (!_modeView) {
  648. _modeView = [[UIView alloc]init];
  649. _modeView.userInteractionEnabled = YES;
  650. }
  651. return _modeView;
  652. }
  653. - (UIScrollView *)scrollView {
  654. if (!_scrollView) {
  655. _scrollView = [[UIScrollView alloc]init];
  656. _scrollView.layer.cornerRadius = 8;
  657. _scrollView.layer.masksToBounds = YES;
  658. _scrollView.delegate = self;
  659. _scrollView.backgroundColor = [UIColor blackColor];
  660. }
  661. return _scrollView;
  662. }
  663. - (UIButton *)backButton {
  664. if (!_backButton) {
  665. _backButton = [[UIButton alloc]init];
  666. [_backButton setImage:[UIImage loadNamed:@"result-return-btn"] forState:UIControlStateNormal];
  667. [_backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  668. }
  669. return _backButton;
  670. }
  671. - (UILabel *)backLabel {
  672. if (!_backLabel) {
  673. _backLabel = [[UILabel alloc]init];
  674. _backLabel.text = @"返回";
  675. _backLabel.textColor = [UIColor whiteColor];
  676. }
  677. return _backLabel;
  678. }
  679. - (UILabel *)deleteLabel {
  680. if (!_deleteLabel) {
  681. _deleteLabel = [[UILabel alloc]init];
  682. _deleteLabel.text = @"删除";
  683. _deleteLabel.textColor = [UIColor whiteColor];
  684. }
  685. return _deleteLabel;
  686. }
  687. - (UIButton *)deleteButton {
  688. if (!_deleteButton) {
  689. _deleteButton = [[UIButton alloc]init];
  690. [_deleteButton setImage:[UIImage loadNamed:@"result-delete-btn"] forState:UIControlStateNormal];
  691. [_deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
  692. }
  693. return _deleteButton;
  694. }
  695. - (UILabel *)curentLabel {
  696. if (!_curentLabel) {
  697. _curentLabel = [[UILabel alloc]init];
  698. _curentLabel.backgroundColor = [UIColor colorWithRed:231/255.0 green:108/255.0 blue:30/255.0 alpha:1];
  699. _curentLabel.layer.cornerRadius = 16;
  700. _curentLabel.layer.masksToBounds = YES;
  701. _curentLabel.textAlignment = NSTextAlignmentCenter;
  702. _curentLabel.textColor = [UIColor whiteColor];
  703. }
  704. return _curentLabel;
  705. }
  706. - (UIImageView *)videoImageView {
  707. if (!_videoImageView) {
  708. _videoImageView = [[UIImageView alloc]init];
  709. _videoImageView.image = [UIImage loadNamed:@"icon_video"];
  710. }
  711. return _videoImageView;
  712. }
  713. @end