Commit 39467b90 authored by yuzheng.tz's avatar yuzheng.tz

发布版本1.8.4 加入横竖屏适配

parent 2b8633e1
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "TZImagePickerController" s.name = "TZImagePickerController"
s.version = "1.8.3" s.version = "1.8.4"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video" s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController" s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT" s.license = "MIT"
s.author = { "banchichen" => "tanzhenios@foxmail.com" } s.author = { "banchichen" => "tanzhenios@foxmail.com" }
s.platform = :ios s.platform = :ios
s.ios.deployment_target = "6.0" s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.8.3" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.8.4" }
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}" s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en_US</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.8.3</string> <string>1.8.4</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -153,7 +153,6 @@ ...@@ -153,7 +153,6 @@
- (UIButton *)selectPhotoButton { - (UIButton *)selectPhotoButton {
if (_selectImageView == nil) { if (_selectImageView == nil) {
UIButton *selectPhotoButton = [[UIButton alloc] init]; UIButton *selectPhotoButton = [[UIButton alloc] init];
selectPhotoButton.frame = CGRectMake(self.tz_width - 44, 0, 44, 44);
[selectPhotoButton addTarget:self action:@selector(selectPhotoButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [selectPhotoButton addTarget:self action:@selector(selectPhotoButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:selectPhotoButton]; [self.contentView addSubview:selectPhotoButton];
_selectPhotoButton = selectPhotoButton; _selectPhotoButton = selectPhotoButton;
...@@ -164,7 +163,6 @@ ...@@ -164,7 +163,6 @@
- (UIImageView *)imageView { - (UIImageView *)imageView {
if (_imageView == nil) { if (_imageView == nil) {
UIImageView *imageView = [[UIImageView alloc] init]; UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(0, 0, self.tz_width, self.tz_height);
imageView.contentMode = UIViewContentModeScaleAspectFill; imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES; imageView.clipsToBounds = YES;
[self.contentView addSubview:imageView]; [self.contentView addSubview:imageView];
...@@ -179,7 +177,6 @@ ...@@ -179,7 +177,6 @@
- (UIImageView *)selectImageView { - (UIImageView *)selectImageView {
if (_selectImageView == nil) { if (_selectImageView == nil) {
UIImageView *selectImageView = [[UIImageView alloc] init]; UIImageView *selectImageView = [[UIImageView alloc] init];
selectImageView.frame = CGRectMake(self.tz_width - 27, 0, 27, 27);
[self.contentView addSubview:selectImageView]; [self.contentView addSubview:selectImageView];
_selectImageView = selectImageView; _selectImageView = selectImageView;
} }
...@@ -189,7 +186,6 @@ ...@@ -189,7 +186,6 @@
- (UIView *)bottomView { - (UIView *)bottomView {
if (_bottomView == nil) { if (_bottomView == nil) {
UIView *bottomView = [[UIView alloc] init]; UIView *bottomView = [[UIView alloc] init];
bottomView.frame = CGRectMake(0, self.tz_height - 17, self.tz_width, 17);
static NSInteger rgb = 0; static NSInteger rgb = 0;
bottomView.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.8]; bottomView.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.8];
[self.contentView addSubview:bottomView]; [self.contentView addSubview:bottomView];
...@@ -201,7 +197,6 @@ ...@@ -201,7 +197,6 @@
- (UIImageView *)videoImgView { - (UIImageView *)videoImgView {
if (_videoImgView == nil) { if (_videoImgView == nil) {
UIImageView *videoImgView = [[UIImageView alloc] init]; UIImageView *videoImgView = [[UIImageView alloc] init];
videoImgView.frame = CGRectMake(8, 0, 17, 17);
[videoImgView setImage:[UIImage imageNamedFromMyBundle:@"VideoSendIcon.png"]]; [videoImgView setImage:[UIImage imageNamedFromMyBundle:@"VideoSendIcon.png"]];
[self.bottomView addSubview:videoImgView]; [self.bottomView addSubview:videoImgView];
_videoImgView = videoImgView; _videoImgView = videoImgView;
...@@ -213,7 +208,6 @@ ...@@ -213,7 +208,6 @@
if (_timeLength == nil) { if (_timeLength == nil) {
UILabel *timeLength = [[UILabel alloc] init]; UILabel *timeLength = [[UILabel alloc] init];
timeLength.font = [UIFont boldSystemFontOfSize:11]; timeLength.font = [UIFont boldSystemFontOfSize:11];
timeLength.frame = CGRectMake(self.videoImgView.tz_right, 0, self.tz_width - self.videoImgView.tz_right - 5, 17);
timeLength.textColor = [UIColor whiteColor]; timeLength.textColor = [UIColor whiteColor];
timeLength.textAlignment = NSTextAlignmentRight; timeLength.textAlignment = NSTextAlignmentRight;
[self.bottomView addSubview:timeLength]; [self.bottomView addSubview:timeLength];
...@@ -225,15 +219,30 @@ ...@@ -225,15 +219,30 @@
- (TZProgressView *)progressView { - (TZProgressView *)progressView {
if (_progressView == nil) { if (_progressView == nil) {
_progressView = [[TZProgressView alloc] init]; _progressView = [[TZProgressView alloc] init];
static CGFloat progressWH = 20;
CGFloat progressXY = (self.tz_width - progressWH) / 2;
_progressView.hidden = YES; _progressView.hidden = YES;
_progressView.frame = CGRectMake(progressXY, progressXY, progressWH, progressWH);
[self addSubview:_progressView]; [self addSubview:_progressView];
} }
return _progressView; return _progressView;
} }
- (void)layoutSubviews {
[super layoutSubviews];
_selectPhotoButton.frame = CGRectMake(self.tz_width - 44, 0, 44, 44);
_selectImageView.frame = CGRectMake(self.tz_width - 27, 0, 27, 27);
_imageView.frame = CGRectMake(0, 0, self.tz_width, self.tz_height);
static CGFloat progressWH = 20;
CGFloat progressXY = (self.tz_width - progressWH) / 2;
_progressView.frame = CGRectMake(progressXY, progressXY, progressWH, progressWH);
_bottomView.frame = CGRectMake(0, self.tz_height - 17, self.tz_width, 17);
_videoImgView.frame = CGRectMake(8, 0, 17, 17);
_timeLength.frame = CGRectMake(self.videoImgView.tz_right, 0, self.tz_width - self.videoImgView.tz_right - 5, 17);
self.type = (NSInteger)self.model.type;
self.showSelectBtn = self.showSelectBtn;
}
@end @end
@interface TZAlbumCell () @interface TZAlbumCell ()
......
...@@ -52,8 +52,7 @@ ...@@ -52,8 +52,7 @@
} }
- (void)configPreviewView { - (void)configPreviewView {
_previewView = [[TZPhotoPreviewView alloc] initWithFrame:self.view.bounds]; _previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
_previewView.scrollView.frame = self.view.bounds;
_previewView.model = self.model; _previewView.model = self.model;
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[_previewView setSingleTapGestureBlock:^{ [_previewView setSingleTapGestureBlock:^{
...@@ -63,12 +62,11 @@ ...@@ -63,12 +62,11 @@
} }
- (void)configBottomToolBar { - (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)]; _toolBar = [[UIView alloc] initWithFrame:CGRectZero];
CGFloat rgb = 34 / 255.0; CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7]; _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
_doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_doneButton.titleLabel.font = [UIFont systemFontOfSize:16]; _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
...@@ -93,6 +91,17 @@ ...@@ -93,6 +91,17 @@
[self.view addSubview:_toolBar]; [self.view addSubview:_toolBar];
} }
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_previewView.frame = self.view.bounds;
_previewView.scrollView.frame = self.view.bounds;
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_toolBar.frame = CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44);
}
#pragma mark - Click Event #pragma mark - Click Event
- (void)signleTapAction { - (void)signleTapAction {
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
@implementation TZImageManager @implementation TZImageManager
static CGSize AssetGridThumbnailSize; CGSize AssetGridThumbnailSize;
static CGFloat TZScreenWidth; CGFloat TZScreenWidth;
static CGFloat TZScreenScale; CGFloat TZScreenScale;
static TZImageManager *manager; static TZImageManager *manager;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
...@@ -34,12 +34,7 @@ static dispatch_once_t onceToken; ...@@ -34,12 +34,7 @@ static dispatch_once_t onceToken;
// manager.cachingImageManager.allowsCachingHighQualityImages = YES; // manager.cachingImageManager.allowsCachingHighQualityImages = YES;
} }
TZScreenWidth = [UIScreen mainScreen].bounds.size.width; [manager configTZScreenWidth];
// 测试发现,如果scale在plus真机上取到3.0,内存会增大特别多。故这里写死成2.0
TZScreenScale = 2.0;
if (TZScreenWidth > 700) {
TZScreenScale = 1.5;
}
}); });
return manager; return manager;
} }
...@@ -55,12 +50,23 @@ static dispatch_once_t onceToken; ...@@ -55,12 +50,23 @@ static dispatch_once_t onceToken;
} }
- (void)setColumnNumber:(NSInteger)columnNumber { - (void)setColumnNumber:(NSInteger)columnNumber {
[self configTZScreenWidth];
_columnNumber = columnNumber; _columnNumber = columnNumber;
CGFloat margin = 4; CGFloat margin = 4;
CGFloat itemWH = (TZScreenWidth - 2 * margin - 4) / columnNumber - margin; CGFloat itemWH = (TZScreenWidth - 2 * margin - 4) / columnNumber - margin;
AssetGridThumbnailSize = CGSizeMake(itemWH * TZScreenScale, itemWH * TZScreenScale); AssetGridThumbnailSize = CGSizeMake(itemWH * TZScreenScale, itemWH * TZScreenScale);
} }
- (void)configTZScreenWidth {
TZScreenWidth = [UIScreen mainScreen].bounds.size.width;
// 测试发现,如果scale在plus真机上取到3.0,内存会增大特别多。故这里写死成2.0
TZScreenScale = 2.0;
if (TZScreenWidth > 700) {
TZScreenScale = 1.5;
}
}
- (ALAssetsLibrary *)assetLibrary { - (ALAssetsLibrary *)assetLibrary {
if (_assetLibrary == nil) _assetLibrary = [[ALAssetsLibrary alloc] init]; if (_assetLibrary == nil) _assetLibrary = [[ALAssetsLibrary alloc] init];
return _assetLibrary; return _assetLibrary;
...@@ -450,7 +456,7 @@ static dispatch_once_t onceToken; ...@@ -450,7 +456,7 @@ static dispatch_once_t onceToken;
CGFloat aspectRatio = phAsset.pixelWidth / (CGFloat)phAsset.pixelHeight; CGFloat aspectRatio = phAsset.pixelWidth / (CGFloat)phAsset.pixelHeight;
CGFloat pixelWidth = photoWidth * TZScreenScale * 1.5; CGFloat pixelWidth = photoWidth * TZScreenScale * 1.5;
// 超宽图片 // 超宽图片
if (aspectRatio > 1) { if (aspectRatio > 1.8) {
pixelWidth = pixelWidth * aspectRatio; pixelWidth = pixelWidth * aspectRatio;
} }
// 超高图片 // 超高图片
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// //
// Created by 谭真 on 15/12/24. // Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved. // Copyright © 2015年 谭真. All rights reserved.
// version 1.8.3 - 2017.07.15 // version 1.8.4 - 2017.07.22
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController // 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
/* /*
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// //
// Created by 谭真 on 15/12/24. // Created by 谭真 on 15/12/24.
// Copyright © 2015年 谭真. All rights reserved. // Copyright © 2015年 谭真. All rights reserved.
// version 1.8.3 - 2017.07.15 // version 1.8.4 - 2017.07.22
// 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController // 更多信息,请前往项目的github地址:https://github.com/banchichen/TZImagePickerController
#import "TZImagePickerController.h" #import "TZImagePickerController.h"
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
self.navigationBar.barStyle = UIBarStyleBlack; self.navigationBar.barStyle = UIBarStyleBlack;
self.navigationBar.translucent = YES; self.navigationBar.translucent = YES;
[TZImageManager manager].shouldFixOrientation = NO; [TZImageManager manager].shouldFixOrientation = NO;
// Default appearance, you can reset these after this method // Default appearance, you can reset these after this method
// 默认的外观,你可以在这个方法后重置 // 默认的外观,你可以在这个方法后重置
...@@ -112,7 +111,6 @@ ...@@ -112,7 +111,6 @@
}else{ }else{
[UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque; [UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque;
} }
} }
- (void)viewWillDisappear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated {
...@@ -319,17 +317,14 @@ ...@@ -319,17 +317,14 @@
[_progressHUD setBackgroundColor:[UIColor clearColor]]; [_progressHUD setBackgroundColor:[UIColor clearColor]];
_HUDContainer = [[UIView alloc] init]; _HUDContainer = [[UIView alloc] init];
_HUDContainer.frame = CGRectMake((self.view.tz_width - 120) / 2, (self.view.tz_height - 90) / 2, 120, 90);
_HUDContainer.layer.cornerRadius = 8; _HUDContainer.layer.cornerRadius = 8;
_HUDContainer.clipsToBounds = YES; _HUDContainer.clipsToBounds = YES;
_HUDContainer.backgroundColor = [UIColor darkGrayColor]; _HUDContainer.backgroundColor = [UIColor darkGrayColor];
_HUDContainer.alpha = 0.7; _HUDContainer.alpha = 0.7;
_HUDIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; _HUDIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
_HUDIndicatorView.frame = CGRectMake(45, 15, 30, 30);
_HUDLabel = [[UILabel alloc] init]; _HUDLabel = [[UILabel alloc] init];
_HUDLabel.frame = CGRectMake(0,40, 120, 50);
_HUDLabel.textAlignment = NSTextAlignmentCenter; _HUDLabel.textAlignment = NSTextAlignmentCenter;
_HUDLabel.text = self.processHintStr; _HUDLabel.text = self.processHintStr;
_HUDLabel.font = [UIFont systemFontOfSize:15]; _HUDLabel.font = [UIFont systemFontOfSize:15];
...@@ -389,8 +384,8 @@ ...@@ -389,8 +384,8 @@
if (_cropRect.size.width > 0) { if (_cropRect.size.width > 0) {
return _cropRect; return _cropRect;
} }
CGFloat cropViewWH = self.view.tz_width; CGFloat cropViewWH = MIN(self.view.tz_width, self.view.tz_height) / 3 * 2;
return CGRectMake(0, (self.view.tz_height - self.view.tz_width) / 2, cropViewWH, cropViewWH); return CGRectMake((self.view.tz_width - cropViewWH) / 2, (self.view.tz_height - cropViewWH) / 2, cropViewWH, cropViewWH);
} }
- (void)setTimeout:(NSInteger)timeout { - (void)setTimeout:(NSInteger)timeout {
...@@ -500,14 +495,40 @@ ...@@ -500,14 +495,40 @@
[super pushViewController:viewController animated:animated]; [super pushViewController:viewController animated:animated];
} }
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (void)dealloc { - (void)dealloc {
// NSLog(@"%@ dealloc",NSStringFromClass(self.class)); // NSLog(@"%@ dealloc",NSStringFromClass(self.class));
} }
#pragma mark - UIContentContainer
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
if (![UIApplication sharedApplication].statusBarHidden) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (iOS7Later && !TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
});
}
self.cropRect = CGRectZero;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (![UIApplication sharedApplication].statusBarHidden) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (iOS7Later && !TZ_isGlobalHideStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
});
}
self.cropRect = CGRectZero;
}
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_HUDContainer.frame = CGRectMake((self.view.tz_width - 120) / 2, (self.view.tz_height - 90) / 2, 120, 90);
_HUDIndicatorView.frame = CGRectMake(45, 15, 30, 30);
_HUDLabel.frame = CGRectMake(0,40, 120, 50);
}
#pragma mark - Public #pragma mark - Public
- (void)cancelButtonClick { - (void)cancelButtonClick {
...@@ -521,12 +542,6 @@ ...@@ -521,12 +542,6 @@
} }
- (void)callDelegateMethod { - (void)callDelegateMethod {
/*
// 兼容旧版本
if ([self.pickerDelegate respondsToSelector:@selector(imagePickerControllerDidCancel:)]) {
[self.pickerDelegate imagePickerControllerDidCancel:self];
}
*/
if ([self.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) { if ([self.pickerDelegate respondsToSelector:@selector(tz_imagePickerControllerDidCancel:)]) {
[self.pickerDelegate tz_imagePickerControllerDidCancel:self]; [self.pickerDelegate tz_imagePickerControllerDidCancel:self];
} }
...@@ -586,19 +601,7 @@ ...@@ -586,19 +601,7 @@
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (!_tableView) { if (!_tableView) {
CGFloat top = 0; _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
CGFloat tableViewHeight = 0;
if (self.navigationController.navigationBar.isTranslucent) {
top = 44;
if (iOS7Later && !TZ_isGlobalHideStatusBar) top += 20;
tableViewHeight = self.view.tz_height - top;
} else {
CGFloat navigationHeight = 44;
if (iOS7Later && !TZ_isGlobalHideStatusBar) navigationHeight += 20;
tableViewHeight = self.view.tz_height - navigationHeight;
}
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, tableViewHeight) style:UITableViewStylePlain];
_tableView.rowHeight = 70; _tableView.rowHeight = 70;
_tableView.tableFooterView = [[UIView alloc] init]; _tableView.tableFooterView = [[UIView alloc] init];
_tableView.dataSource = self; _tableView.dataSource = self;
...@@ -617,6 +620,26 @@ ...@@ -617,6 +620,26 @@
// NSLog(@"%@ dealloc",NSStringFromClass(self.class)); // NSLog(@"%@ dealloc",NSStringFromClass(self.class));
} }
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGFloat top = 0;
CGFloat tableViewHeight = 0;
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight;
if (iOS7Later && !TZ_isGlobalHideStatusBar) top += 20;
tableViewHeight = self.view.tz_height - top;
} else {
CGFloat navigationHeight = naviBarHeight;
if (iOS7Later && !TZ_isGlobalHideStatusBar) navigationHeight += 20;
tableViewHeight = self.view.tz_height - navigationHeight;
}
_tableView.frame = CGRectMake(0, top, self.view.tz_width, tableViewHeight);
}
#pragma mark - UITableViewDataSource && Delegate #pragma mark - UITableViewDataSource && Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
......
...@@ -20,24 +20,30 @@ ...@@ -20,24 +20,30 @@
@interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate> { @interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate> {
NSMutableArray *_models; NSMutableArray *_models;
UIView *_bottomToolBar;
UIButton *_previewButton; UIButton *_previewButton;
UIButton *_doneButton; UIButton *_doneButton;
UIImageView *_numberImageView; UIImageView *_numberImageView;
UILabel *_numberLabel; UILabel *_numberLabel;
UIButton *_originalPhotoButton; UIButton *_originalPhotoButton;
UILabel *_originalPhotoLabel; UILabel *_originalPhotoLabel;
UIView *_divideLine;
BOOL _shouldScrollToBottom; BOOL _shouldScrollToBottom;
BOOL _showTakePhotoBtn; BOOL _showTakePhotoBtn;
CGFloat _offsetItemCount;
} }
@property CGRect previousPreheatRect; @property CGRect previousPreheatRect;
@property (nonatomic, assign) BOOL isSelectOriginalPhoto; @property (nonatomic, assign) BOOL isSelectOriginalPhoto;
@property (nonatomic, strong) TZCollectionView *collectionView; @property (nonatomic, strong) TZCollectionView *collectionView;
@property (strong, nonatomic) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) UIImagePickerController *imagePickerVc; @property (nonatomic, strong) UIImagePickerController *imagePickerVc;
@property (strong, nonatomic) CLLocation *location; @property (strong, nonatomic) CLLocation *location;
@end @end
static CGSize AssetGridThumbnailSize; static CGSize AssetGridThumbnailSize;
static CGFloat itemMargin = 5;
@implementation TZPhotoPickerController @implementation TZPhotoPickerController
...@@ -74,6 +80,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -74,6 +80,7 @@ static CGSize AssetGridThumbnailSize;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:tzImagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:tzImagePickerVc action:@selector(cancelButtonClick)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:tzImagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:tzImagePickerVc action:@selector(cancelButtonClick)];
_showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture); _showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture);
// [self resetCachedAssets]; // [self resetCachedAssets];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
} }
- (void)fetchAssetModels { - (void)fetchAssetModels {
...@@ -128,29 +135,13 @@ static CGSize AssetGridThumbnailSize; ...@@ -128,29 +135,13 @@ static CGSize AssetGridThumbnailSize;
- (void)configCollectionView { - (void)configCollectionView {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; _layout = [[UICollectionViewFlowLayout alloc] init];
CGFloat margin = 5; _collectionView = [[TZCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
CGFloat itemWH = (self.view.tz_width - (self.columnNumber + 1) * margin) / self.columnNumber;
layout.itemSize = CGSizeMake(itemWH, itemWH);
layout.minimumInteritemSpacing = margin;
layout.minimumLineSpacing = margin;
CGFloat top = 0;
CGFloat collectionViewHeight = 0;
if (self.navigationController.navigationBar.isTranslucent) {
top = 44;
if (iOS7Later && !TZ_isGlobalHideStatusBar) top += 20;
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - 50 - top : self.view.tz_height - top;;
} else {
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - 50 : self.view.tz_height;
}
_collectionView = [[TZCollectionView alloc] initWithFrame:CGRectMake(0, top, self.view.tz_width, collectionViewHeight) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor whiteColor]; _collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.dataSource = self; _collectionView.dataSource = self;
_collectionView.delegate = self; _collectionView.delegate = self;
_collectionView.alwaysBounceHorizontal = NO; _collectionView.alwaysBounceHorizontal = NO;
_collectionView.contentInset = UIEdgeInsetsMake(margin, margin, margin, margin); _collectionView.contentInset = UIEdgeInsetsMake(itemMargin, itemMargin, itemMargin, itemMargin);
if (_showTakePhotoBtn && tzImagePickerVc.allowTakePicture ) { if (_showTakePhotoBtn && tzImagePickerVc.allowTakePicture ) {
_collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + self.columnNumber) / self.columnNumber) * self.view.tz_width); _collectionView.contentSize = CGSizeMake(self.view.tz_width, ((_model.count + self.columnNumber) / self.columnNumber) * self.view.tz_width);
...@@ -187,27 +178,12 @@ static CGSize AssetGridThumbnailSize; ...@@ -187,27 +178,12 @@ static CGSize AssetGridThumbnailSize;
- (void)configBottomToolBar { - (void)configBottomToolBar {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (!tzImagePickerVc.showSelectBtn) return; if (!tzImagePickerVc.showSelectBtn) return;
CGFloat yOffset = 0; _bottomToolBar = [[UIView alloc] initWithFrame:CGRectZero];
if (!self.navigationController.navigationBar.isHidden) {
yOffset = self.view.tz_height - 50;
} else {
CGFloat navigationHeight = 44;
if (iOS7Later) navigationHeight += 20;
yOffset = self.view.tz_height - 50 - navigationHeight;
}
UIView *bottomToolBar = [[UIView alloc] initWithFrame:CGRectMake(0, yOffset, self.view.tz_width, 50)];
CGFloat rgb = 253 / 255.0; CGFloat rgb = 253 / 255.0;
bottomToolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0]; _bottomToolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:1.0];
CGFloat previewWidth = [tzImagePickerVc.previewBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.width + 2;
if (!tzImagePickerVc.allowPreview) {
previewWidth = 0.0;
}
_previewButton = [UIButton buttonWithType:UIButtonTypeCustom]; _previewButton = [UIButton buttonWithType:UIButtonTypeCustom];
_previewButton.frame = CGRectMake(10, 3, previewWidth, 44);
_previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth;
[_previewButton addTarget:self action:@selector(previewButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_previewButton addTarget:self action:@selector(previewButtonClick) forControlEvents:UIControlEventTouchUpInside];
_previewButton.titleLabel.font = [UIFont systemFontOfSize:16]; _previewButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_previewButton setTitle:tzImagePickerVc.previewBtnTitleStr forState:UIControlStateNormal]; [_previewButton setTitle:tzImagePickerVc.previewBtnTitleStr forState:UIControlStateNormal];
...@@ -217,9 +193,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -217,9 +193,7 @@ static CGSize AssetGridThumbnailSize;
_previewButton.enabled = tzImagePickerVc.selectedModels.count; _previewButton.enabled = tzImagePickerVc.selectedModels.count;
if (tzImagePickerVc.allowPickingOriginalPhoto) { if (tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [tzImagePickerVc.fullImageBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size.width;
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom]; _originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
_originalPhotoButton.frame = CGRectMake(CGRectGetMaxX(_previewButton.frame), self.view.tz_height - 50, fullImageWidth + 56, 50);
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0); _originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
_originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16]; _originalPhotoButton.titleLabel.font = [UIFont systemFontOfSize:16];
...@@ -233,7 +207,6 @@ static CGSize AssetGridThumbnailSize; ...@@ -233,7 +207,6 @@ static CGSize AssetGridThumbnailSize;
_originalPhotoButton.enabled = tzImagePickerVc.selectedModels.count > 0; _originalPhotoButton.enabled = tzImagePickerVc.selectedModels.count > 0;
_originalPhotoLabel = [[UILabel alloc] init]; _originalPhotoLabel = [[UILabel alloc] init];
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
_originalPhotoLabel.textAlignment = NSTextAlignmentLeft; _originalPhotoLabel.textAlignment = NSTextAlignmentLeft;
_originalPhotoLabel.font = [UIFont systemFontOfSize:16]; _originalPhotoLabel.font = [UIFont systemFontOfSize:16];
_originalPhotoLabel.textColor = [UIColor blackColor]; _originalPhotoLabel.textColor = [UIColor blackColor];
...@@ -241,7 +214,6 @@ static CGSize AssetGridThumbnailSize; ...@@ -241,7 +214,6 @@ static CGSize AssetGridThumbnailSize;
} }
_doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 3, 44, 44);
_doneButton.titleLabel.font = [UIFont systemFontOfSize:16]; _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal]; [_doneButton setTitle:tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
...@@ -251,12 +223,10 @@ static CGSize AssetGridThumbnailSize; ...@@ -251,12 +223,10 @@ static CGSize AssetGridThumbnailSize;
_doneButton.enabled = tzImagePickerVc.selectedModels.count || tzImagePickerVc.alwaysEnableDoneBtn; _doneButton.enabled = tzImagePickerVc.selectedModels.count || tzImagePickerVc.alwaysEnableDoneBtn;
_numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoNumberIconImageName]]; _numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoNumberIconImageName]];
_numberImageView.frame = CGRectMake(self.view.tz_width - 56 - 28, 10, 30, 30);
_numberImageView.hidden = tzImagePickerVc.selectedModels.count <= 0; _numberImageView.hidden = tzImagePickerVc.selectedModels.count <= 0;
_numberImageView.backgroundColor = [UIColor clearColor]; _numberImageView.backgroundColor = [UIColor clearColor];
_numberLabel = [[UILabel alloc] init]; _numberLabel = [[UILabel alloc] init];
_numberLabel.frame = _numberImageView.frame;
_numberLabel.font = [UIFont systemFontOfSize:15]; _numberLabel.font = [UIFont systemFontOfSize:15];
_numberLabel.textColor = [UIColor whiteColor]; _numberLabel.textColor = [UIColor whiteColor];
_numberLabel.textAlignment = NSTextAlignmentCenter; _numberLabel.textAlignment = NSTextAlignmentCenter;
...@@ -264,21 +234,85 @@ static CGSize AssetGridThumbnailSize; ...@@ -264,21 +234,85 @@ static CGSize AssetGridThumbnailSize;
_numberLabel.hidden = tzImagePickerVc.selectedModels.count <= 0; _numberLabel.hidden = tzImagePickerVc.selectedModels.count <= 0;
_numberLabel.backgroundColor = [UIColor clearColor]; _numberLabel.backgroundColor = [UIColor clearColor];
UIView *divide = [[UIView alloc] init]; _divideLine = [[UIView alloc] init];
CGFloat rgb2 = 222 / 255.0; CGFloat rgb2 = 222 / 255.0;
divide.backgroundColor = [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0]; _divideLine.backgroundColor = [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0];
divide.frame = CGRectMake(0, 0, self.view.tz_width, 1);
[bottomToolBar addSubview:divide]; [_bottomToolBar addSubview:_divideLine];
[bottomToolBar addSubview:_previewButton]; [_bottomToolBar addSubview:_previewButton];
[bottomToolBar addSubview:_doneButton]; [_bottomToolBar addSubview:_doneButton];
[bottomToolBar addSubview:_numberImageView]; [_bottomToolBar addSubview:_numberImageView];
[bottomToolBar addSubview:_numberLabel]; [_bottomToolBar addSubview:_numberLabel];
[self.view addSubview:bottomToolBar]; [self.view addSubview:_bottomToolBar];
[self.view addSubview:_originalPhotoButton]; [self.view addSubview:_originalPhotoButton];
[_originalPhotoButton addSubview:_originalPhotoLabel]; [_originalPhotoButton addSubview:_originalPhotoLabel];
} }
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
CGFloat top = 0;
CGFloat collectionViewHeight = 0;
CGFloat naviBarHeight = self.navigationController.navigationBar.tz_height;
if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight;
if (iOS7Later && !TZ_isGlobalHideStatusBar) top += 20;
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - 50 - top : self.view.tz_height - top;;
} else {
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - 50 : self.view.tz_height;
}
_collectionView.frame = CGRectMake(0, top, self.view.tz_width, collectionViewHeight);
CGFloat itemWH = (self.view.tz_width - (self.columnNumber + 1) * itemMargin) / self.columnNumber;
_layout.itemSize = CGSizeMake(itemWH, itemWH);
_layout.minimumInteritemSpacing = itemMargin;
_layout.minimumLineSpacing = itemMargin;
[_collectionView setCollectionViewLayout:_layout];
if (_offsetItemCount > 0) {
CGFloat offsetY = _offsetItemCount * (_layout.itemSize.height + _layout.minimumLineSpacing);
[_collectionView setContentOffset:CGPointMake(0, offsetY)];
}
CGFloat yOffset = 0;
if (!self.navigationController.navigationBar.isHidden) {
yOffset = self.view.tz_height - 50;
} else {
CGFloat navigationHeight = naviBarHeight;
if (iOS7Later) navigationHeight += 20;
yOffset = self.view.tz_height - 50 - navigationHeight;
}
_bottomToolBar.frame = CGRectMake(0, yOffset, self.view.tz_width, 50);
CGFloat previewWidth = [tzImagePickerVc.previewBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil].size.width + 2;
if (!tzImagePickerVc.allowPreview) {
previewWidth = 0.0;
}
_previewButton.frame = CGRectMake(10, 3, previewWidth, 44);
_previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth;
if (tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [tzImagePickerVc.fullImageBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size.width;
_originalPhotoButton.frame = CGRectMake(CGRectGetMaxX(_previewButton.frame), self.view.tz_height - 50, fullImageWidth + 56, 50);
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
}
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 3, 44, 44);
_numberImageView.frame = CGRectMake(self.view.tz_width - 56 - 28, 10, 30, 30);
_numberLabel.frame = _numberImageView.frame;
_divideLine.frame = CGRectMake(0, 0, self.view.tz_width, 1);
[TZImageManager manager].columnNumber = [TZImageManager manager].columnNumber;
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
[self.collectionView reloadData];
}
}
#pragma mark - Notification
- (void)didChangeStatusBarOrientationNotification:(NSNotification *)noti {
_offsetItemCount = _collectionView.contentOffset.y / (_layout.itemSize.height + _layout.minimumLineSpacing);
}
#pragma mark - Click Event #pragma mark - Click Event
- (void)previewButtonClick { - (void)previewButtonClick {
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
self.backgroundColor = [UIColor blackColor]; self.backgroundColor = [UIColor blackColor];
self.previewView = [[TZPhotoPreviewView alloc] initWithFrame:self.bounds]; self.previewView = [[TZPhotoPreviewView alloc] initWithFrame:CGRectZero];
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[self.previewView setSingleTapGestureBlock:^{ [self.previewView setSingleTapGestureBlock:^{
if (weakSelf.singleTapGestureBlock) { if (weakSelf.singleTapGestureBlock) {
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
_previewView.cropRect = cropRect; _previewView.cropRect = cropRect;
} }
- (void)layoutSubviews {
[super layoutSubviews];
self.previewView.frame = self.bounds;
}
@end @end
...@@ -71,7 +76,6 @@ ...@@ -71,7 +76,6 @@
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) { if (self) {
_scrollView = [[UIScrollView alloc] init]; _scrollView = [[UIScrollView alloc] init];
_scrollView.frame = CGRectMake(10, 0, self.tz_width - 20, self.tz_height);
_scrollView.bouncesZoom = YES; _scrollView.bouncesZoom = YES;
_scrollView.maximumZoomScale = 2.5; _scrollView.maximumZoomScale = 2.5;
_scrollView.minimumZoomScale = 1.0; _scrollView.minimumZoomScale = 1.0;
...@@ -111,10 +115,6 @@ ...@@ -111,10 +115,6 @@
- (void)configProgressView { - (void)configProgressView {
_progressView = [[TZProgressView alloc] init]; _progressView = [[TZProgressView alloc] init];
static CGFloat progressWH = 40;
CGFloat progressX = (self.tz_width - progressWH) / 2;
CGFloat progressY = (self.tz_height - progressWH) / 2;
_progressView.frame = CGRectMake(progressX, progressY, progressWH, progressWH);
_progressView.hidden = YES; _progressView.hidden = YES;
[self addSubview:_progressView]; [self addSubview:_progressView];
} }
...@@ -163,7 +163,7 @@ ...@@ -163,7 +163,7 @@
[self bringSubviewToFront:_progressView]; [self bringSubviewToFront:_progressView];
progress = progress > 0.02 ? progress : 0.02; progress = progress > 0.02 ? progress : 0.02;
_progressView.progress = progress; _progressView.progress = progress;
if (self.imageProgressUpdateBlock) { if (self.imageProgressUpdateBlock && progress < 1) {
self.imageProgressUpdateBlock(progress); self.imageProgressUpdateBlock(progress);
} }
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
_scrollView.contentSize = CGSizeMake(newSizeW, newSizeH); _scrollView.contentSize = CGSizeMake(newSizeW, newSizeH);
_scrollView.alwaysBounceVertical = YES; _scrollView.alwaysBounceVertical = YES;
// 2.让scrollView新增滑动区域(裁剪框左上角的图片部分) // 2.让scrollView新增滑动区域(裁剪框左上角的图片部分)
if (contentHeightAdd > 0) { if (contentHeightAdd > 0 || contentWidthAdd > 0) {
_scrollView.contentInset = UIEdgeInsetsMake(contentHeightAdd, _cropRect.origin.x, 0, 0); _scrollView.contentInset = UIEdgeInsetsMake(contentHeightAdd, _cropRect.origin.x, 0, 0);
} else { } else {
_scrollView.contentInset = UIEdgeInsetsZero; _scrollView.contentInset = UIEdgeInsetsZero;
...@@ -238,6 +238,17 @@ ...@@ -238,6 +238,17 @@
} }
} }
- (void)layoutSubviews {
[super layoutSubviews];
_scrollView.frame = CGRectMake(10, 0, self.tz_width - 20, self.tz_height);
static CGFloat progressWH = 40;
CGFloat progressX = (self.tz_width - progressWH) / 2;
CGFloat progressY = (self.tz_height - progressWH) / 2;
_progressView.frame = CGRectMake(progressX, progressY, progressWH, progressWH);
[self recoverSubviews];
}
#pragma mark - UITapGestureRecognizer Event #pragma mark - UITapGestureRecognizer Event
- (void)doubleTap:(UITapGestureRecognizer *)tap { - (void)doubleTap:(UITapGestureRecognizer *)tap {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
@interface TZPhotoPreviewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIScrollViewDelegate> { @interface TZPhotoPreviewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIScrollViewDelegate> {
UICollectionView *_collectionView; UICollectionView *_collectionView;
UICollectionViewFlowLayout *_layout;
NSArray *_photosTemp; NSArray *_photosTemp;
NSArray *_assetsTemp; NSArray *_assetsTemp;
...@@ -29,6 +30,8 @@ ...@@ -29,6 +30,8 @@
UILabel *_numberLabel; UILabel *_numberLabel;
UIButton *_originalPhotoButton; UIButton *_originalPhotoButton;
UILabel *_originalPhotoLabel; UILabel *_originalPhotoLabel;
CGFloat _offsetItemCount;
} }
@property (nonatomic, assign) BOOL isHideNaviBar; @property (nonatomic, assign) BOOL isHideNaviBar;
@property (nonatomic, strong) UIView *cropBgView; @property (nonatomic, strong) UIView *cropBgView;
...@@ -51,10 +54,10 @@ ...@@ -51,10 +54,10 @@
self.isSelectOriginalPhoto = _tzImagePickerVc.isSelectOriginalPhoto; self.isSelectOriginalPhoto = _tzImagePickerVc.isSelectOriginalPhoto;
} }
[self configCollectionView]; [self configCollectionView];
[self configCropView];
[self configCustomNaviBar]; [self configCustomNaviBar];
[self configBottomToolBar]; [self configBottomToolBar];
self.view.clipsToBounds = YES; self.view.clipsToBounds = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
} }
- (void)setPhotos:(NSMutableArray *)photos { - (void)setPhotos:(NSMutableArray *)photos {
...@@ -88,15 +91,15 @@ ...@@ -88,15 +91,15 @@
- (void)configCustomNaviBar { - (void)configCustomNaviBar {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
_naviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.tz_width, 64)]; _naviBar = [[UIView alloc] initWithFrame:CGRectZero];
_naviBar.backgroundColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:0.7]; _naviBar.backgroundColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:0.7];
_backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 44, 44)]; _backButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_backButton setImage:[UIImage imageNamedFromMyBundle:@"navi_back.png"] forState:UIControlStateNormal]; [_backButton setImage:[UIImage imageNamedFromMyBundle:@"navi_back.png"] forState:UIControlStateNormal];
[_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
_selectButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.tz_width - 54, 10, 42, 42)]; _selectButton = [[UIButton alloc] initWithFrame:CGRectZero];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal]; [_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoDefImageName] forState:UIControlStateNormal];
[_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoSelImageName] forState:UIControlStateSelected]; [_selectButton setImage:[UIImage imageNamedFromMyBundle:tzImagePickerVc.photoSelImageName] forState:UIControlStateSelected];
[_selectButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside]; [_selectButton addTarget:self action:@selector(select:) forControlEvents:UIControlEventTouchUpInside];
...@@ -108,15 +111,13 @@ ...@@ -108,15 +111,13 @@
} }
- (void)configBottomToolBar { - (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)]; _toolBar = [[UIView alloc] initWithFrame:CGRectZero];
static CGFloat rgb = 34 / 255.0; static CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7]; _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_tzImagePickerVc.allowPickingOriginalPhoto) { if (_tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [_tzImagePickerVc.fullImageBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size.width;
_originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom]; _originalPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
_originalPhotoButton.frame = CGRectMake(0, 0, fullImageWidth + 56, 44);
_originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0); _originalPhotoButton.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
_originalPhotoButton.backgroundColor = [UIColor clearColor]; _originalPhotoButton.backgroundColor = [UIColor clearColor];
[_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_originalPhotoButton addTarget:self action:@selector(originalPhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
...@@ -129,7 +130,6 @@ ...@@ -129,7 +130,6 @@
[_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoOriginSelImageName] forState:UIControlStateSelected]; [_originalPhotoButton setImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoOriginSelImageName] forState:UIControlStateSelected];
_originalPhotoLabel = [[UILabel alloc] init]; _originalPhotoLabel = [[UILabel alloc] init];
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 42, 0, 80, 44);
_originalPhotoLabel.textAlignment = NSTextAlignmentLeft; _originalPhotoLabel.textAlignment = NSTextAlignmentLeft;
_originalPhotoLabel.font = [UIFont systemFontOfSize:13]; _originalPhotoLabel.font = [UIFont systemFontOfSize:13];
_originalPhotoLabel.textColor = [UIColor whiteColor]; _originalPhotoLabel.textColor = [UIColor whiteColor];
...@@ -138,7 +138,6 @@ ...@@ -138,7 +138,6 @@
} }
_doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_doneButton.titleLabel.font = [UIFont systemFontOfSize:16]; _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_doneButton setTitle:_tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal]; [_doneButton setTitle:_tzImagePickerVc.doneBtnTitleStr forState:UIControlStateNormal];
...@@ -146,11 +145,9 @@ ...@@ -146,11 +145,9 @@
_numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoNumberIconImageName]]; _numberImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamedFromMyBundle:_tzImagePickerVc.photoNumberIconImageName]];
_numberImageView.backgroundColor = [UIColor clearColor]; _numberImageView.backgroundColor = [UIColor clearColor];
_numberImageView.frame = CGRectMake(self.view.tz_width - 56 - 28, 7, 30, 30);
_numberImageView.hidden = _tzImagePickerVc.selectedModels.count <= 0; _numberImageView.hidden = _tzImagePickerVc.selectedModels.count <= 0;
_numberLabel = [[UILabel alloc] init]; _numberLabel = [[UILabel alloc] init];
_numberLabel.frame = _numberImageView.frame;
_numberLabel.font = [UIFont systemFontOfSize:15]; _numberLabel.font = [UIFont systemFontOfSize:15];
_numberLabel.textColor = [UIColor whiteColor]; _numberLabel.textColor = [UIColor whiteColor];
_numberLabel.textAlignment = NSTextAlignmentCenter; _numberLabel.textAlignment = NSTextAlignmentCenter;
...@@ -167,12 +164,9 @@ ...@@ -167,12 +164,9 @@
} }
- (void)configCollectionView { - (void)configCollectionView {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; _layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(self.view.tz_width + 20, self.view.tz_height); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(-10, 0, self.view.tz_width + 20, self.view.tz_height) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor blackColor]; _collectionView.backgroundColor = [UIColor blackColor];
_collectionView.dataSource = self; _collectionView.dataSource = self;
_collectionView.delegate = self; _collectionView.delegate = self;
...@@ -188,17 +182,20 @@ ...@@ -188,17 +182,20 @@
- (void)configCropView { - (void)configCropView {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (!_tzImagePickerVc.showSelectBtn && _tzImagePickerVc.allowCrop) { if (!_tzImagePickerVc.showSelectBtn && _tzImagePickerVc.allowCrop) {
[_cropView removeFromSuperview];
[_cropBgView removeFromSuperview];
_cropBgView = [UIView new]; _cropBgView = [UIView new];
_cropBgView.userInteractionEnabled = NO; _cropBgView.userInteractionEnabled = NO;
_cropBgView.backgroundColor = [UIColor clearColor];
_cropBgView.frame = self.view.bounds; _cropBgView.frame = self.view.bounds;
_cropBgView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_cropBgView]; [self.view addSubview:_cropBgView];
[TZImageCropManager overlayClippingWithView:_cropBgView cropRect:_tzImagePickerVc.cropRect containerView:self.view needCircleCrop:_tzImagePickerVc.needCircleCrop]; [TZImageCropManager overlayClippingWithView:_cropBgView cropRect:_tzImagePickerVc.cropRect containerView:self.view needCircleCrop:_tzImagePickerVc.needCircleCrop];
_cropView = [UIView new]; _cropView = [UIView new];
_cropView.userInteractionEnabled = NO; _cropView.userInteractionEnabled = NO;
_cropView.backgroundColor = [UIColor clearColor];
_cropView.frame = _tzImagePickerVc.cropRect; _cropView.frame = _tzImagePickerVc.cropRect;
_cropView.backgroundColor = [UIColor clearColor];
_cropView.layer.borderColor = [UIColor whiteColor].CGColor; _cropView.layer.borderColor = [UIColor whiteColor].CGColor;
_cropView.layer.borderWidth = 1.0; _cropView.layer.borderWidth = 1.0;
if (_tzImagePickerVc.needCircleCrop) { if (_tzImagePickerVc.needCircleCrop) {
...@@ -212,6 +209,46 @@ ...@@ -212,6 +209,46 @@
} }
} }
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_naviBar.frame = CGRectMake(0, 0, self.view.tz_width, 64);
_backButton.frame = CGRectMake(10, 10, 44, 44);
_selectButton.frame = CGRectMake(self.view.tz_width - 54, 10, 42, 42);
_layout.itemSize = CGSizeMake(self.view.tz_width + 20, self.view.tz_height);
_layout.minimumInteritemSpacing = 0;
_layout.minimumLineSpacing = 0;
_collectionView.frame = CGRectMake(-10, 0, self.view.tz_width + 20, self.view.tz_height);
[_collectionView setCollectionViewLayout:_layout];
if (_offsetItemCount > 0) {
CGFloat offsetX = _offsetItemCount * _layout.itemSize.width;
[_collectionView setContentOffset:CGPointMake(offsetX, 0)];
}
[_collectionView reloadData];
_toolBar.frame = CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44);
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (_tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [_tzImagePickerVc.fullImageBtnTitleStr boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size.width;
_originalPhotoButton.frame = CGRectMake(0, 0, fullImageWidth + 56, 44);
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 42, 0, 80, 44);
}
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_numberImageView.frame = CGRectMake(self.view.tz_width - 56 - 28, 7, 30, 30);
_numberLabel.frame = _numberImageView.frame;
[self configCropView];
}
#pragma mark - Notification
- (void)didChangeStatusBarOrientationNotification:(NSNotification *)noti {
_offsetItemCount = _collectionView.contentOffset.x / _layout.itemSize.width;
}
#pragma mark - Click Event #pragma mark - Click Event
- (void)select:(UIButton *)selectButton { - (void)select:(UIButton *)selectButton {
...@@ -287,7 +324,7 @@ ...@@ -287,7 +324,7 @@
- (void)doneButtonClick { - (void)doneButtonClick {
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
// 如果图片正在从iCloud同步中,提醒用户 // 如果图片正在从iCloud同步中,提醒用户
if (_progress > 0 && _progress < 1) { if (_progress > 0 && _progress < 1 && (_selectButton.isSelected || !_tzImagePickerVc.selectedModels.count )) {
_alertView = [_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]]; _alertView = [_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]];
return; return;
} }
...@@ -370,11 +407,14 @@ ...@@ -370,11 +407,14 @@
}; };
} }
__weak typeof(_tzImagePickerVc) weakTzImagePickerVc = _tzImagePickerVc; __weak typeof(_tzImagePickerVc) weakTzImagePickerVc = _tzImagePickerVc;
__weak typeof(_collectionView) weakCollectionView = _collectionView;
__weak typeof(cell) weakCell = cell;
[cell setImageProgressUpdateBlock:^(double progress) { [cell setImageProgressUpdateBlock:^(double progress) {
weakSelf.progress = progress; weakSelf.progress = progress;
if (progress >= 1) { if (progress >= 1) {
if (weakSelf.alertView) { if (weakSelf.alertView && [weakCollectionView.visibleCells containsObject:weakCell]) {
[weakTzImagePickerVc hideAlertView:weakSelf.alertView]; [weakTzImagePickerVc hideAlertView:weakSelf.alertView];
weakSelf.alertView = nil;
[weakSelf doneButtonClick]; [weakSelf doneButtonClick];
} }
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
@interface TZVideoPlayerController () { @interface TZVideoPlayerController () {
AVPlayer *_player; AVPlayer *_player;
AVPlayerLayer *_playerLayer;
UIButton *_playButton; UIButton *_playButton;
UIImage *_cover; UIImage *_cover;
...@@ -60,9 +61,9 @@ ...@@ -60,9 +61,9 @@
[[TZImageManager manager] getVideoWithAsset:_model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) { [[TZImageManager manager] getVideoWithAsset:_model.asset completion:^(AVPlayerItem *playerItem, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
_player = [AVPlayer playerWithPlayerItem:playerItem]; _player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player]; _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
playerLayer.frame = self.view.bounds; _playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer]; [self.view.layer addSublayer:_playerLayer];
[self addProgressObserver]; [self addProgressObserver];
[self configPlayButton]; [self configPlayButton];
[self configBottomToolBar]; [self configBottomToolBar];
...@@ -86,7 +87,6 @@ ...@@ -86,7 +87,6 @@
- (void)configPlayButton { - (void)configPlayButton {
_playButton = [UIButton buttonWithType:UIButtonTypeCustom]; _playButton = [UIButton buttonWithType:UIButtonTypeCustom];
_playButton.frame = CGRectMake(0, 64, self.view.tz_width, self.view.tz_height - 64 - 44);
[_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlay.png"] forState:UIControlStateNormal]; [_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlay.png"] forState:UIControlStateNormal];
[_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlayHL.png"] forState:UIControlStateHighlighted]; [_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlayHL.png"] forState:UIControlStateHighlighted];
[_playButton addTarget:self action:@selector(playButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_playButton addTarget:self action:@selector(playButtonClick) forControlEvents:UIControlEventTouchUpInside];
...@@ -94,12 +94,11 @@ ...@@ -94,12 +94,11 @@
} }
- (void)configBottomToolBar { - (void)configBottomToolBar {
_toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44)]; _toolBar = [[UIView alloc] initWithFrame:CGRectZero];
CGFloat rgb = 34 / 255.0; CGFloat rgb = 34 / 255.0;
_toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7]; _toolBar.backgroundColor = [UIColor colorWithRed:rgb green:rgb blue:rgb alpha:0.7];
_doneButton = [UIButton buttonWithType:UIButtonTypeCustom]; _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_doneButton.titleLabel.font = [UIFont systemFontOfSize:16]; _doneButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
...@@ -114,6 +113,17 @@ ...@@ -114,6 +113,17 @@
[self.view addSubview:_toolBar]; [self.view addSubview:_toolBar];
} }
#pragma mark - Layout
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_playerLayer.frame = self.view.bounds;
_playButton.frame = CGRectMake(0, 64, self.view.tz_width, self.view.tz_height - 64 - 44);
_doneButton.frame = CGRectMake(self.view.tz_width - 44 - 12, 0, 44, 44);
_toolBar.frame = CGRectMake(0, self.view.tz_height - 44, self.view.tz_width, 44);
}
#pragma mark - Click Event #pragma mark - Click Event
- (void)playButtonClick { - (void)playButtonClick {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment