123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- //
- // TZGifPhotoPreviewController.m
- // TZImagePickerController
- //
- // Created by ttouch on 2016/12/13.
- // Copyright © 2016年 谭真. All rights reserved.
- //
- #import "TZGifPhotoPreviewController.h"
- #import "TZImagePickerController.h"
- #import "TZAssetModel.h"
- #import "UIView+Layout.h"
- #import "TZPhotoPreviewCell.h"
- #import "TZImageManager.h"
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- @interface TZGifPhotoPreviewController () {
- UIView *_toolBar;
- UIButton *_doneButton;
- UIProgressView *_progress;
-
- TZPhotoPreviewView *_previewView;
-
- UIStatusBarStyle _originStatusBarStyle;
- }
- @end
- @implementation TZGifPhotoPreviewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor blackColor];
- TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
- if (tzImagePickerVc) {
- self.navigationItem.title = [NSString stringWithFormat:@"GIF %@",tzImagePickerVc.previewBtnTitleStr];
- }
- [self configPreviewView];
- [self configBottomToolBar];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [UIApplication sharedApplication].statusBarStyle = _originStatusBarStyle;
- }
- - (void)configPreviewView {
- _previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
- _previewView.model = self.model;
- __weak typeof(self) weakSelf = self;
- [_previewView setSingleTapGestureBlock:^{
- __strong typeof(weakSelf) strongSelf = weakSelf;
- [strongSelf signleTapAction];
- }];
- [self.view addSubview:_previewView];
- }
- - (void)configBottomToolBar {
- _toolBar = [[UIView alloc] initWithFrame:CGRectZero];
- CGFloat rgb = 34 / 255.0;
- _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
-
- _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
- [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
- TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
- if (tzImagePickerVc) {
- [_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
- [_doneButton setTitleColor:tzImagePickerVc.oKButtonTitleColorNormal forState:UIControlStateNormal];
- } else {
- [_doneButton setTitle:[NSBundle tz_localizedStringForKey:@"Done"] forState:UIControlStateNormal];
- [_doneButton setTitleColor:[UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0] forState:UIControlStateNormal];
- }
- [_toolBar addSubview:_doneButton];
-
- UILabel *byteLabel = [[UILabel alloc] init];
- byteLabel.textColor = [UIColor whiteColor];
- byteLabel.font = [UIFont systemFontOfSize:13];
- byteLabel.frame = CGRectMake(10, 0, 100, 44);
- [[TZImageManager manager] getPhotosBytesWithArray:@[_model] completion:^(NSString *totalBytes) {
- byteLabel.text = totalBytes;
- }];
- [_toolBar addSubview:byteLabel];
-
- [self.view addSubview:_toolBar];
-
- if (tzImagePickerVc.gifPreviewPageUIConfigBlock) {
- tzImagePickerVc.gifPreviewPageUIConfigBlock(_toolBar, _doneButton);
- }
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- TZImagePickerController *tzImagePicker = (TZImagePickerController *)self.navigationController;
- if (tzImagePicker && [tzImagePicker isKindOfClass:[TZImagePickerController class]]) {
- return tzImagePicker.statusBarStyle;
- }
- return [super preferredStatusBarStyle];
- }
- #pragma mark - Layout
- - (void)viewDidLayoutSubviews {
- [super viewDidLayoutSubviews];
-
- _previewView.frame = self.view.bounds;
- _previewView.scrollView.frame = self.view.bounds;
- CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 44 + (83 - 49) : 44;
- _toolBar.frame = CGRectMake(0, self.view.tz_height - toolBarHeight, self.view.tz_width, toolBarHeight);
- _doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
-
- TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
- if (tzImagePickerVc.gifPreviewPageDidLayoutSubviewsBlock) {
- tzImagePickerVc.gifPreviewPageDidLayoutSubviewsBlock(_toolBar, _doneButton);
- }
- }
- #pragma mark - Click Event
- - (void)signleTapAction {
- _toolBar.hidden = !_toolBar.isHidden;
- [self.navigationController setNavigationBarHidden:_toolBar.isHidden];
- TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
- if (_toolBar.isHidden) {
- [UIApplication sharedApplication].statusBarHidden = YES;
- } else if (tzImagePickerVc.needShowStatusBar) {
- [UIApplication sharedApplication].statusBarHidden = NO;
- }
- }
- - (void)doneButtonClick {
- if (self.navigationController) {
- TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
- if (imagePickerVc.autoDismiss) {
- [self.navigationController dismissViewControllerAnimated:YES completion:^{
- [self callDelegateMethod];
- }];
- } else {
- [self callDelegateMethod];
- }
- } else {
- [self dismissViewControllerAnimated:YES completion:^{
- [self callDelegateMethod];
- }];
- }
- }
- - (void)callDelegateMethod {
- TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
- UIImage *animatedImage = _previewView.imageView.image;
- if ([imagePickerVc.pickerDelegate respondsToSelector:@selector(imagePickerController:didFinishPickingGifImage:sourceAssets:)]) {
- [imagePickerVc.pickerDelegate imagePickerController:imagePickerVc didFinishPickingGifImage:animatedImage sourceAssets:_model.asset];
- }
- if (imagePickerVc.didFinishPickingGifImageHandle) {
- imagePickerVc.didFinishPickingGifImageHandle(animatedImage,_model.asset);
- }
- }
- #pragma clang diagnostic pop
- @end
|