TZGifPhotoPreviewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. @interface TZGifPhotoPreviewController () {
  15. UIView *_toolBar;
  16. UIButton *_doneButton;
  17. UIProgressView *_progress;
  18. TZPhotoPreviewView *_previewView;
  19. UIStatusBarStyle _originStatusBarStyle;
  20. }
  21. @end
  22. @implementation TZGifPhotoPreviewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.view.backgroundColor = [UIColor blackColor];
  26. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  27. if (tzImagePickerVc) {
  28. self.navigationItem.title = [NSString stringWithFormat:@"GIF %@",tzImagePickerVc.previewBtnTitleStr];
  29. }
  30. [self configPreviewView];
  31. [self configBottomToolBar];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear:animated];
  35. _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
  36. [UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque;
  37. }
  38. - (void)viewWillDisappear:(BOOL)animated {
  39. [super viewWillDisappear:animated];
  40. [UIApplication sharedApplication].statusBarStyle = _originStatusBarStyle;
  41. }
  42. - (void)configPreviewView {
  43. _previewView = [[TZPhotoPreviewView alloc] initWithFrame:self.view.bounds];
  44. _previewView.scrollView.frame = self.view.bounds;
  45. _previewView.model = self.model;
  46. __weak typeof(self) weakSelf = self;
  47. [_previewView setSingleTapGestureBlock:^{
  48. [weakSelf signleTapAction];
  49. }];
  50. [self.view addSubview:_previewView];
  51. }
  52. - (void)configBottomToolBar {
  53. _toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)];
  54. CGFloat rgb = 34 / 255.0;
  55. _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
  56. _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
  57. _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
  58. _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
  59. [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
  60. TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
  61. if (tzImagePickerVc) {
  62. [_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
  63. [_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
  64. } else {
  65. [_doneButton setTitle:[NSBundle tz_localizedStringForKey:@"Done"] forState:UIControlStateNormal];
  66. [_doneButton setTitleColor:[UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0] forState:UIControlStateNormal];
  67. }
  68. [_toolBar addSubview:_doneButton];
  69. UILabel *byteLabel = [[UILabel alloc] init];
  70. byteLabel.textColor = [UIColor whiteColor];
  71. byteLabel.font = [UIFont systemFontOfSize:13];
  72. byteLabel.frame = CGRectMake(10, 0, 100, 44);
  73. [[TZImageManager manager] getPhotosBytesWithArray:@[_model] completion:^(NSString *totalBytes) {
  74. byteLabel.text = totalBytes;
  75. }];
  76. [_toolBar addSubview:byteLabel];
  77. [self.view addSubview:_toolBar];
  78. }
  79. #pragma mark - Click Event
  80. - (void)signleTapAction {
  81. _toolBar.hidden = !_toolBar.isHidden;
  82. [self.navigationController setNavigationBarHidden:_toolBar.isHidden];
  83. if (iOS7Later) [UIApplication sharedApplication].statusBarHidden = _toolBar.isHidden;
  84. }
  85. - (void)doneButtonClick {
  86. TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
  87. if (self.navigationController) {
  88. if (imagePickerVc.autoDismiss) {
  89. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  90. [self callDelegateMethod];
  91. }];
  92. }
  93. } else {
  94. [self dismissViewControllerAnimated:YES completion:^{
  95. [self callDelegateMethod];
  96. }];
  97. }
  98. }
  99. - (void)callDelegateMethod {
  100. TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
  101. UIImage *animatedImage = _previewView.imageView.image;
  102. if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingGifImage:sourceAssets:)]) {
  103. [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingGifImage:animatedImage sourceAssets:_model.asset];
  104. }
  105. if (imagePickerVc.didFinishPickingGifImageHandle) {
  106. imagePickerVc.didFinishPickingGifImageHandle(animatedImage,_model.asset);
  107. }
  108. }
  109. @end