TZGifPhotoPreviewController.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // TZGifPhotoPreviewController.m
  3. // TZImagePickerController
  4. //
  5. // Created by ttouch on 2016/12/13.
  6. // Copyright © 2016年 谭真. All rights reserved.
  7. //
  8. #import "TZGifPhotoPreviewController.h"
  9. #import "TZImagePickerController.h"
  10. #import "TZAssetModel.h"
  11. #import "UIView+Layout.h"
  12. #import "TZPhotoPreviewCell.h"
  13. #import "TZImageManager.h"
  14. #pragma clang diagnostic push
  15. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  16. @interface TZGifPhotoPreviewController () {
  17. UIView *_toolBar;
  18. UIButton *_doneButton;
  19. UIProgressView *_progress;
  20. TZPhotoPreviewView *_previewView;
  21. UIStatusBarStyle _originStatusBarStyle;
  22. }
  23. @end
  24. @implementation TZGifPhotoPreviewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.view.backgroundColor = [UIColor blackColor];
  28. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  29. if (tzImagePickerVc) {
  30. self.navigationItem.title = [NSString stringWithFormat:@"GIF %@",tzImagePickerVc.previewBtnTitleStr];
  31. }
  32. [self configPreviewView];
  33. [self configBottomToolBar];
  34. }
  35. - (void)viewWillAppear:(BOOL)animated {
  36. [super viewWillAppear:animated];
  37. _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
  38. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  39. }
  40. - (void)viewWillDisappear:(BOOL)animated {
  41. [super viewWillDisappear:animated];
  42. [UIApplication sharedApplication].statusBarStyle = _originStatusBarStyle;
  43. }
  44. - (void)configPreviewView {
  45. _previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
  46. _previewView.model = self.model;
  47. __weak typeof(self) weakSelf = self;
  48. [_previewView setSingleTapGestureBlock:^{
  49. __strong typeof(weakSelf) strongSelf = weakSelf;
  50. [strongSelf signleTapAction];
  51. }];
  52. [self.view addSubview:_previewView];
  53. }
  54. - (void)configBottomToolBar {
  55. _toolBar = [[UIView alloc] initWithFrame:CGRectZero];
  56. CGFloat rgb = 34 / 255.0;
  57. _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
  58. _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
  59. _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
  60. [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
  61. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  62. if (tzImagePickerVc) {
  63. [_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
  64. [_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
  65. } else {
  66. [_doneButton setTitle:[NSBundle tz_localizedStringForKey:@"Done"] forState:UIControlStateNormal];
  67. [_doneButton setTitleColor:[UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0] forState:UIControlStateNormal];
  68. }
  69. [_toolBar addSubview:_doneButton];
  70. UILabel *byteLabel = [[UILabel alloc] init];
  71. byteLabel.textColor = [UIColor whiteColor];
  72. byteLabel.font = [UIFont systemFontOfSize:13];
  73. byteLabel.frame = CGRectMake(10, 0, 100, 44);
  74. [[TZImageManager manager] getPhotosBytesWithArray:@[_model] completion:^(NSString *totalBytes) {
  75. byteLabel.text = totalBytes;
  76. }];
  77. [_toolBar addSubview:byteLabel];
  78. [self.view addSubview:_toolBar];
  79. if (tzImagePickerVc.gifPreviewPageUIConfigBlock) {
  80. tzImagePickerVc.gifPreviewPageUIConfigBlock(_toolBar, _doneButton);
  81. }
  82. }
  83. - (UIStatusBarStyle)preferredStatusBarStyle {
  84. TZImagePickerController *tzImagePicker = (TZImagePickerController *)self.navigationController;
  85. if (tzImagePicker && [tzImagePicker isKindOfClass:[TZImagePickerController class]]) {
  86. return tzImagePicker.statusBarStyle;
  87. }
  88. return [super preferredStatusBarStyle];
  89. }
  90. #pragma mark - Layout
  91. - (void)viewDidLayoutSubviews {
  92. [super viewDidLayoutSubviews];
  93. _previewView.frame = self.view.bounds;
  94. _previewView.scrollView.frame = self.view.bounds;
  95. CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 44 + (83 - 49) : 44;
  96. _toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight);
  97. _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
  98. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  99. if (tzImagePickerVc.gifPreviewPageDidLayoutSubviewsBlock) {
  100. tzImagePickerVc.gifPreviewPageDidLayoutSubviewsBlock(_toolBar, _doneButton);
  101. }
  102. }
  103. #pragma mark - Click Event
  104. - (void)signleTapAction {
  105. _toolBar.hidden = !_toolBar.isHidden;
  106. [self.navigationController setNavigationBarHidden:_toolBar.isHidden];
  107. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  108. if (_toolBar.isHidden) {
  109. [UIApplication sharedApplication].statusBarHidden = YES;
  110. } else if (tzImagePickerVc.needShowStatusBar) {
  111. [UIApplication sharedApplication].statusBarHidden = NO;
  112. }
  113. }
  114. - (void)doneButtonClick {
  115. if (self.navigationController) {
  116. TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
  117. if (imagePickerVc.autoDismiss) {
  118. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  119. [self callDelegateMethod];
  120. }];
  121. } else {
  122. [self callDelegateMethod];
  123. }
  124. } else {
  125. [self dismissViewControllerAnimated:YES completion:^{
  126. [self callDelegateMethod];
  127. }];
  128. }
  129. }
  130. - (void)callDelegateMethod {
  131. TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
  132. UIImage *animatedImage = _previewView.imageView.image;
  133. if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingGifImage:sourceAssets:)]) {
  134. [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingGifImage:animatedImage sourceAssets:_model.asset];
  135. }
  136. if (imagePickerVc.didFinishPickingGifImageHandle) {
  137. imagePickerVc.didFinishPickingGifImageHandle(animatedImage,_model.asset);
  138. }
  139. }
  140. #pragma clang diagnostic pop
  141. @end