Commit 9e8f7ec8 authored by yuzheng.tz's avatar yuzheng.tz

移除iOS6和7的适配代码

parent c8c2fe3f
...@@ -11,5 +11,5 @@ Pod::Spec.new do |s| ...@@ -11,5 +11,5 @@ Pod::Spec.new do |s|
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,bundle}" s.resources = "TZImagePickerController/TZImagePickerController/*.{png,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
s.frameworks = "Photos","AssetsLibrary" s.frameworks = "Photos"
end end
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
902938D81EE2D02C000F2F8F /* TZLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 902938D71EE2D02C000F2F8F /* TZLocationManager.m */; }; 902938D81EE2D02C000F2F8F /* TZLocationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 902938D71EE2D02C000F2F8F /* TZLocationManager.m */; };
9038D5911C3974F0007DE549 /* TZTestCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9038D5901C3974F0007DE549 /* TZTestCell.m */; }; 9038D5911C3974F0007DE549 /* TZTestCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9038D5901C3974F0007DE549 /* TZTestCell.m */; };
903996931F447604005E77C2 /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 903996921F447604005E77C2 /* Photos.framework */; }; 903996931F447604005E77C2 /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 903996921F447604005E77C2 /* Photos.framework */; };
903996951F447609005E77C2 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 903996941F447609005E77C2 /* AssetsLibrary.framework */; };
90A74B85203287C200D84C2A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 90A74B83203287C200D84C2A /* Localizable.strings */; }; 90A74B85203287C200D84C2A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 90A74B83203287C200D84C2A /* Localizable.strings */; };
90CE84AE1C3A89EF003D0779 /* TZImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 90CE84AD1C3A89EF003D0779 /* TZImageManager.m */; }; 90CE84AE1C3A89EF003D0779 /* TZImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 90CE84AD1C3A89EF003D0779 /* TZImageManager.m */; };
90CE84B71C3BABB6003D0779 /* TZVideoPlayerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 90CE84B61C3BABB6003D0779 /* TZVideoPlayerController.m */; }; 90CE84B71C3BABB6003D0779 /* TZVideoPlayerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 90CE84B61C3BABB6003D0779 /* TZVideoPlayerController.m */; };
...@@ -173,7 +172,6 @@ ...@@ -173,7 +172,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
903996951F447609005E77C2 /* AssetsLibrary.framework in Frameworks */,
903996931F447604005E77C2 /* Photos.framework in Frameworks */, 903996931F447604005E77C2 /* Photos.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
......
...@@ -30,22 +30,14 @@ ...@@ -30,22 +30,14 @@
- (void)setModel:(TZAssetModel *)model { - (void)setModel:(TZAssetModel *)model {
_model = model; _model = model;
if (iOS8Later) { self.representedAssetIdentifier = model.asset.localIdentifier;
self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset];
}
if (self.useCachedImage && model.cachedImage) { if (self.useCachedImage && model.cachedImage) {
self.imageView.image = model.cachedImage; self.imageView.image = model.cachedImage;
} else { } else {
self.model.cachedImage = nil; self.model.cachedImage = nil;
int32_t imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { int32_t imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
// Set the cell's thumbnail image if it's still showing the same asset. // Set the cell's thumbnail image if it's still showing the same asset.
if (!iOS8Later) { if ([self.representedAssetIdentifier isEqualToString:model.asset.localIdentifier]) {
self.imageView.image = photo;
self.model.cachedImage = photo;
[self hideProgressView];
return;
}
if ([self.representedAssetIdentifier isEqualToString:[[TZImageManager manager] getAssetIdentifier:model.asset]]) {
self.imageView.image = photo; self.imageView.image = photo;
self.model.cachedImage = photo; self.model.cachedImage = photo;
} else { } else {
...@@ -385,7 +377,7 @@ ...@@ -385,7 +377,7 @@
/// For fitting iOS6 /// For fitting iOS6
- (void)layoutSubviews { - (void)layoutSubviews {
if (iOS7Later) [super layoutSubviews]; [super layoutSubviews];
_selectedCountButton.frame = CGRectMake(self.tz_width - 24 - 30, 23, 24, 24); _selectedCountButton.frame = CGRectMake(self.tz_width - 24 - 30, 23, 24, 24);
NSInteger titleHeight = ceil(self.titleLabel.font.lineHeight); NSInteger titleHeight = ceil(self.titleLabel.font.lineHeight);
self.titleLabel.frame = CGRectMake(80, (self.tz_height - titleHeight) / 2, self.tz_width - 80 - 50, titleHeight); self.titleLabel.frame = CGRectMake(80, (self.tz_height - titleHeight) / 2, self.tz_width - 80 - 50, titleHeight);
...@@ -397,7 +389,7 @@ ...@@ -397,7 +389,7 @@
} }
- (void)layoutSublayersOfLayer:(CALayer *)layer { - (void)layoutSublayersOfLayer:(CALayer *)layer {
if (iOS7Later) [super layoutSublayersOfLayer:layer]; [super layoutSublayersOfLayer:layer];
} }
#pragma mark - Lazy load #pragma mark - Lazy load
......
...@@ -20,17 +20,17 @@ typedef enum : NSUInteger { ...@@ -20,17 +20,17 @@ typedef enum : NSUInteger {
@class PHAsset; @class PHAsset;
@interface TZAssetModel : NSObject @interface TZAssetModel : NSObject
@property (nonatomic, strong) id asset; ///< PHAsset or ALAsset @property (nonatomic, strong) PHAsset *asset;
@property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No @property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No
@property (nonatomic, assign) TZAssetModelMediaType type; @property (nonatomic, assign) TZAssetModelMediaType type;
@property (assign, nonatomic) BOOL needOscillatoryAnimation; @property (assign, nonatomic) BOOL needOscillatoryAnimation;
@property (nonatomic, copy) NSString *timeLength; @property (nonatomic, copy) NSString *timeLength;
@property (strong, nonatomic) UIImage *cachedImage; @property (strong, nonatomic) UIImage *cachedImage;
/// Init a photo dataModel With a asset /// Init a photo dataModel With a PHAsset
/// 用一个PHAsset/ALAsset实例,初始化一个照片模型 /// 用一个PHAsset实例,初始化一个照片模型
+ (instancetype)modelWithAsset:(id)asset type:(TZAssetModelMediaType)type; + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type;
+ (instancetype)modelWithAsset:(id)asset type:(TZAssetModelMediaType)type timeLength:(NSString *)timeLength; + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type timeLength:(NSString *)timeLength;
@end @end
...@@ -40,7 +40,7 @@ typedef enum : NSUInteger { ...@@ -40,7 +40,7 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) NSString *name; ///< The album name @property (nonatomic, strong) NSString *name; ///< The album name
@property (nonatomic, assign) NSInteger count; ///< Count of photos the album contain @property (nonatomic, assign) NSInteger count; ///< Count of photos the album contain
@property (nonatomic, strong) id result; ///< PHFetchResult<PHAsset> or ALAssetsGroup<ALAsset> @property (nonatomic, strong) PHFetchResult *result;
@property (nonatomic, strong) NSArray *models; @property (nonatomic, strong) NSArray *models;
@property (nonatomic, strong) NSArray *selectedModels; @property (nonatomic, strong) NSArray *selectedModels;
...@@ -48,6 +48,6 @@ typedef enum : NSUInteger { ...@@ -48,6 +48,6 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) BOOL isCameraRoll; @property (nonatomic, assign) BOOL isCameraRoll;
- (void)setResult:(id)result needFetchAssets:(BOOL)needFetchAssets; - (void)setResult:(PHFetchResult *)result needFetchAssets:(BOOL)needFetchAssets;
@end @end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
@implementation TZAssetModel @implementation TZAssetModel
+ (instancetype)modelWithAsset:(id)asset type:(TZAssetModelMediaType)type{ + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type{
TZAssetModel *model = [[TZAssetModel alloc] init]; TZAssetModel *model = [[TZAssetModel alloc] init];
model.asset = asset; model.asset = asset;
model.isSelected = NO; model.isSelected = NO;
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
return model; return model;
} }
+ (instancetype)modelWithAsset:(id)asset type:(TZAssetModelMediaType)type timeLength:(NSString *)timeLength { + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type timeLength:(NSString *)timeLength {
TZAssetModel *model = [self modelWithAsset:asset type:type]; TZAssetModel *model = [self modelWithAsset:asset type:type];
model.timeLength = timeLength; model.timeLength = timeLength;
return model; return model;
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
@implementation TZAlbumModel @implementation TZAlbumModel
- (void)setResult:(id)result needFetchAssets:(BOOL)needFetchAssets { - (void)setResult:(PHFetchResult *)result needFetchAssets:(BOOL)needFetchAssets {
_result = result; _result = result;
if (needFetchAssets) { if (needFetchAssets) {
[[TZImageManager manager] getAssetsFromFetchResult:result completion:^(NSArray<TZAssetModel *> *models) { [[TZImageManager manager] getAssetsFromFetchResult:result completion:^(NSArray<TZAssetModel *> *models) {
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
[selectedAssets addObject:model.asset]; [selectedAssets addObject:model.asset];
} }
for (TZAssetModel *model in _models) { for (TZAssetModel *model in _models) {
if ([[TZImageManager manager] isAssetsArray:selectedAssets containAsset:model.asset]) { if ([selectedAssets containsObject:model.asset]) {
self.selectedCount ++; self.selectedCount ++;
} }
} }
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
_originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
[UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
} }
- (void)viewWillDisappear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated {
...@@ -119,13 +119,11 @@ ...@@ -119,13 +119,11 @@
_toolBar.hidden = !_toolBar.isHidden; _toolBar.hidden = !_toolBar.isHidden;
[self.navigationController setNavigationBarHidden:_toolBar.isHidden]; [self.navigationController setNavigationBarHidden:_toolBar.isHidden];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (iOS7Later) {
if (_toolBar.isHidden) { if (_toolBar.isHidden) {
[UIApplication sharedApplication].statusBarHidden = YES; [UIApplication sharedApplication].statusBarHidden = YES;
} else if (tzImagePickerVc.needShowStatusBar) { } else if (tzImagePickerVc.needShowStatusBar) {
[UIApplication sharedApplication].statusBarHidden = NO; [UIApplication sharedApplication].statusBarHidden = NO;
} }
}
} }
- (void)doneButtonClick { - (void)doneButtonClick {
......
...@@ -54,26 +54,26 @@ ...@@ -54,26 +54,26 @@
- (void)getAllAlbums:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage needFetchAssets:(BOOL)needFetchAssets completion:(void (^)(NSArray<TZAlbumModel *> *models))completion; - (void)getAllAlbums:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage needFetchAssets:(BOOL)needFetchAssets completion:(void (^)(NSArray<TZAlbumModel *> *models))completion;
/// Get Assets 获得Asset数组 /// Get Assets 获得Asset数组
- (void)getAssetsFromFetchResult:(id)result completion:(void (^)(NSArray<TZAssetModel *> *models))completion; - (void)getAssetsFromFetchResult:(PHFetchResult *)result completion:(void (^)(NSArray<TZAssetModel *> *models))completion;
- (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(NSArray<TZAssetModel *> *models))completion; - (void)getAssetsFromFetchResult:(PHFetchResult *)result allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(NSArray<TZAssetModel *> *models))completion;
- (void)getAssetFromFetchResult:(id)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(TZAssetModel *model))completion; - (void)getAssetFromFetchResult:(PHFetchResult *)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(TZAssetModel *model))completion;
/// Get photo 获得照片 /// Get photo 获得照片
- (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion; - (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion;
- (int32_t)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (int32_t)getPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (int32_t)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (int32_t)getPhotoWithAsset:(PHAsset *)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (int32_t)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed; - (int32_t)getPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
- (int32_t)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed; - (int32_t)getPhotoWithAsset:(PHAsset *)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
- (int32_t)requestImageDataForAsset:(id)asset completion:(void (^)(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler; - (int32_t)requestImageDataForAsset:(PHAsset *)asset completion:(void (^)(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler;
/// Get full Image 获取原图 /// Get full Image 获取原图
/// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。 /// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
- (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion; - (void)getOriginalPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
- (void)getOriginalPhotoWithAsset:(id)asset newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (void)getOriginalPhotoWithAsset:(PHAsset *)asset newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
// 该方法中,completion只会走一次 // 该方法中,completion只会走一次
- (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion; - (void)getOriginalPhotoDataWithAsset:(PHAsset *)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
- (void)getOriginalPhotoDataWithAsset:(id)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion; - (void)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
/// Save photo 保存照片 /// Save photo 保存照片
- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion; - (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion;
...@@ -84,38 +84,33 @@ ...@@ -84,38 +84,33 @@
- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion; - (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion;
/// Get video 获得视频 /// Get video 获得视频
- (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion; - (void)getVideoWithAsset:(PHAsset *)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion;
- (void)getVideoWithAsset:(id)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *, NSDictionary *))completion; - (void)getVideoWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *, NSDictionary *))completion;
/// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480 /// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480
- (void)getVideoOutputPathWithAsset:(id)asset success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure; - (void)getVideoOutputPathWithAsset:(PHAsset *)asset success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure;
- (void)getVideoOutputPathWithAsset:(id)asset presetName:(NSString *)presetName success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure; - (void)getVideoOutputPathWithAsset:(PHAsset *)asset presetName:(NSString *)presetName success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure;
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success: /// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
- (void)getVideoOutputPathWithAsset:(id)asset completion:(void (^)(NSString *outputPath))completion __attribute__((deprecated("Use -getVideoOutputPathWithAsset:failure:success:"))); - (void)getVideoOutputPathWithAsset:(PHAsset *)asset completion:(void (^)(NSString *outputPath))completion __attribute__((deprecated("Use -getVideoOutputPathWithAsset:failure:success:")));
/// Get photo bytes 获得一组照片的大小 /// Get photo bytes 获得一组照片的大小
- (void)getPhotosBytesWithArray:(NSArray *)photos completion:(void (^)(NSString *totalBytes))completion; - (void)getPhotosBytesWithArray:(NSArray *)photos completion:(void (^)(NSString *totalBytes))completion;
/// Judge is a assets array contain the asset 判断一个assets数组是否包含这个asset - (BOOL)isCameraRollAlbum:(PHAssetCollection *)metadata;
- (BOOL)isAssetsArray:(NSArray *)assets containAsset:(id)asset;
- (NSString *)getAssetIdentifier:(id)asset;
- (BOOL)isCameraRollAlbum:(id)metadata;
/// 检查照片大小是否满足最小要求 /// 检查照片大小是否满足最小要求
- (BOOL)isPhotoSelectableWithAsset:(id)asset; - (BOOL)isPhotoSelectableWithAsset:(PHAsset *)asset;
- (CGSize)photoSizeWithAsset:(id)asset;
/// 修正图片转向 /// 修正图片转向
- (UIImage *)fixOrientation:(UIImage *)aImage; - (UIImage *)fixOrientation:(UIImage *)aImage;
/// 获取asset的资源类型 /// 获取asset的资源类型
- (TZAssetModelMediaType)getAssetType:(id)asset; - (TZAssetModelMediaType)getAssetType:(PHAsset *)asset;
/// 缩放图片至新尺寸 /// 缩放图片至新尺寸
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size; - (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size;
/// 判断asset是否是视频 /// 判断asset是否是视频
- (BOOL)isVideo:(id)asset; - (BOOL)isVideo:(PHAsset *)asset;
@end @end
......
...@@ -25,9 +25,6 @@ ...@@ -25,9 +25,6 @@
#import "TZLocationManager.h" #import "TZLocationManager.h"
#import "TZPhotoPreviewController.h" #import "TZPhotoPreviewController.h"
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
@class TZAlbumCell, TZAssetCell; @class TZAlbumCell, TZAssetCell;
@protocol TZImagePickerControllerDelegate; @protocol TZImagePickerControllerDelegate;
@interface TZImagePickerController : UINavigationController @interface TZImagePickerController : UINavigationController
...@@ -40,7 +37,7 @@ ...@@ -40,7 +37,7 @@
/// This init method just for previewing photos / 用这个初始化方法以预览图片 /// This init method just for previewing photos / 用这个初始化方法以预览图片
- (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index; - (instancetype)initWithSelectedAssets:(NSMutableArray *)selectedAssets selectedPhotos:(NSMutableArray *)selectedPhotos index:(NSInteger)index;
/// This init method for crop photo / 用这个初始化方法以裁剪图片 /// This init method for crop photo / 用这个初始化方法以裁剪图片
- (instancetype)initCropTypeWithAsset:(id)asset photo:(UIImage *)photo completion:(void (^)(UIImage *cropImage,id asset))completion; - (instancetype)initCropTypeWithAsset:(PHAsset *)asset photo:(UIImage *)photo completion:(void (^)(UIImage *cropImage,PHAsset *asset))completion;
#pragma mark - #pragma mark -
/// Default is 9 / 默认最大可选9张图片 /// Default is 9 / 默认最大可选9张图片
...@@ -185,8 +182,8 @@ ...@@ -185,8 +182,8 @@
@property (nonatomic, copy) void (^albumCellDidLayoutSubviewsBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel); @property (nonatomic, copy) void (^albumCellDidLayoutSubviewsBlock)(TZAlbumCell *cell, UIImageView *posterImageView, UILabel *titleLabel);
#pragma mark - #pragma mark -
- (id)showAlertWithTitle:(NSString *)title; - (UIAlertController *)showAlertWithTitle:(NSString *)title;
- (void)hideAlertView:(id)alertView; - (void)hideAlertView:(UIAlertController *)alertView;
- (void)showProgressHUD; - (void)showProgressHUD;
- (void)hideProgressHUD; - (void)hideProgressHUD;
@property (nonatomic, assign) BOOL isSelectOriginalPhoto; @property (nonatomic, assign) BOOL isSelectOriginalPhoto;
...@@ -247,10 +244,8 @@ ...@@ -247,10 +244,8 @@
@property (nonatomic, copy) void (^imagePickerControllerDidCancelHandle)(void); @property (nonatomic, copy) void (^imagePickerControllerDidCancelHandle)(void);
// If user picking a video, this handle will be called. // If user picking a video, this handle will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
// 如果用户选择了一个视频,下面的handle会被执行 // 如果用户选择了一个视频,下面的handle会被执行
// 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象 @property (nonatomic, copy) void (^didFinishPickingVideoHandle)(UIImage *coverImage,PHAsset *asset);
@property (nonatomic, copy) void (^didFinishPickingVideoHandle)(UIImage *coverImage,id asset);
// If user picking a gif image, this callback will be called. // If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行 // 如果用户选择了一个gif图片,下面的handle会被执行
...@@ -279,22 +274,20 @@ ...@@ -279,22 +274,20 @@
- (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker; - (void)tz_imagePickerControllerDidCancel:(TZImagePickerController *)picker;
// If user picking a video, this callback will be called. // If user picking a video, this callback will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
// 如果用户选择了一个视频,下面的handle会被执行 // 如果用户选择了一个视频,下面的handle会被执行
// 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象 - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(PHAsset *)asset;
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset;
// If user picking a gif image, this callback will be called. // If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行 // 如果用户选择了一个gif图片,下面的handle会被执行
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset; - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(PHAsset *)asset;
// Decide album show or not't // Decide album show or not't
// 决定相册显示与否 albumName:相册名字 result:相册原始数据 // 决定相册显示与否 albumName:相册名字 result:相册原始数据
- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result; - (BOOL)isAlbumCanSelect:(NSString *)albumName result:(PHFetchResult *)result;
// Decide asset show or not't // Decide asset show or not't
// 决定照片显示与否 // 决定照片显示与否
- (BOOL)isAssetCanSelect:(id)asset; - (BOOL)isAssetCanSelect:(PHAsset *)asset;
@end @end
...@@ -310,12 +303,6 @@ ...@@ -310,12 +303,6 @@
@end @end
@interface NSString (TzExtension)
- (BOOL)tz_containsString:(NSString *)string;
- (CGSize)tz_calculateSizeWithAttributes:(NSDictionary *)attributes maxSize:(CGSize)maxSize;
@end
@interface TZCommonTools : NSObject @interface TZCommonTools : NSObject
+ (BOOL)tz_isIPhoneX; + (BOOL)tz_isIPhoneX;
+ (CGFloat)tz_statusBarHeight; + (CGFloat)tz_statusBarHeight;
......
...@@ -60,19 +60,15 @@ ...@@ -60,19 +60,15 @@
self.oKButtonTitleColorNormal = [UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0]; self.oKButtonTitleColorNormal = [UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:1.0];
self.oKButtonTitleColorDisabled = [UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:0.5]; self.oKButtonTitleColorDisabled = [UIColor colorWithRed:(83/255.0) green:(179/255.0) blue:(17/255.0) alpha:0.5];
if (iOS7Later) {
self.navigationBar.barTintColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:1.0]; self.navigationBar.barTintColor = [UIColor colorWithRed:(34/255.0) green:(34/255.0) blue:(34/255.0) alpha:1.0];
self.navigationBar.tintColor = [UIColor whiteColor]; self.navigationBar.tintColor = [UIColor whiteColor];
self.automaticallyAdjustsScrollViewInsets = NO; self.automaticallyAdjustsScrollViewInsets = NO;
if (self.needShowStatusBar) [UIApplication sharedApplication].statusBarHidden = NO; if (self.needShowStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
}
} }
- (void)setNaviBgColor:(UIColor *)naviBgColor { - (void)setNaviBgColor:(UIColor *)naviBgColor {
_naviBgColor = naviBgColor; _naviBgColor = naviBgColor;
if (iOS7Later) {
self.navigationBar.barTintColor = naviBgColor; self.navigationBar.barTintColor = naviBgColor;
}
} }
- (void)setNaviTitleColor:(UIColor *)naviTitleColor { - (void)setNaviTitleColor:(UIColor *)naviTitleColor {
...@@ -110,9 +106,9 @@ ...@@ -110,9 +106,9 @@
_isStatusBarDefault = isStatusBarDefault; _isStatusBarDefault = isStatusBarDefault;
if (isStatusBarDefault) { if (isStatusBarDefault) {
self.statusBarStyle = iOS7Later ? UIStatusBarStyleDefault : UIStatusBarStyleBlackOpaque; self.statusBarStyle = UIStatusBarStyleDefault;
} else { } else {
self.statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque; self.statusBarStyle = UIStatusBarStyleLightContent;
} }
} }
...@@ -192,14 +188,12 @@ ...@@ -192,14 +188,12 @@
_tipLabel.text = tipText; _tipLabel.text = tipText;
[self.view addSubview:_tipLabel]; [self.view addSubview:_tipLabel];
if (iOS8Later) {
_settingBtn = [UIButton buttonWithType:UIButtonTypeSystem]; _settingBtn = [UIButton buttonWithType:UIButtonTypeSystem];
[_settingBtn setTitle:self.settingBtnTitleStr forState:UIControlStateNormal]; [_settingBtn setTitle:self.settingBtnTitleStr forState:UIControlStateNormal];
_settingBtn.frame = CGRectMake(0, 180, self.view.tz_width, 44); _settingBtn.frame = CGRectMake(0, 180, self.view.tz_width, 44);
_settingBtn.titleLabel.font = [UIFont systemFontOfSize:18]; _settingBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_settingBtn addTarget:self action:@selector(settingBtnClick) forControlEvents:UIControlEventTouchUpInside]; [_settingBtn addTarget:self action:@selector(settingBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_settingBtn]; [self.view addSubview:_settingBtn];
}
if ([TZImageManager authorizationStatus] == 0) { if ([TZImageManager authorizationStatus] == 0) {
_timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(observeAuthrizationStatusChange) userInfo:nil repeats:NO]; _timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(observeAuthrizationStatusChange) userInfo:nil repeats:NO];
...@@ -237,7 +231,7 @@ ...@@ -237,7 +231,7 @@
} }
/// This init method for crop photo / 用这个初始化方法以裁剪图片 /// This init method for crop photo / 用这个初始化方法以裁剪图片
- (instancetype)initCropTypeWithAsset:(id)asset photo:(UIImage *)photo completion:(void (^)(UIImage *cropImage,id asset))completion { - (instancetype)initCropTypeWithAsset:(PHAsset *)asset photo:(UIImage *)photo completion:(void (^)(UIImage *cropImage,PHAsset *asset))completion {
TZPhotoPreviewController *previewVc = [[TZPhotoPreviewController alloc] init]; TZPhotoPreviewController *previewVc = [[TZPhotoPreviewController alloc] init];
self = [super initWithRootViewController:previewVc]; self = [super initWithRootViewController:previewVc];
if (self) { if (self) {
...@@ -402,27 +396,15 @@ ...@@ -402,27 +396,15 @@
} }
} }
- (id)showAlertWithTitle:(NSString *)title { - (UIAlertController *)showAlertWithTitle:(NSString *)title {
if (iOS8Later) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
return alertController; return alertController;
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil, nil];
[alertView show];
return alertView;
}
} }
- (void)hideAlertView:(id)alertView { - (void)hideAlertView:(UIAlertController *)alertView {
if ([alertView isKindOfClass:[UIAlertController class]]) { [alertView dismissViewControllerAnimated:YES completion:nil];
UIAlertController *alertC = alertView;
[alertC dismissViewControllerAnimated:YES completion:nil];
} else if ([alertView isKindOfClass:[UIAlertView class]]) {
UIAlertView *alertV = alertView;
[alertV dismissWithClickedButtonIndex:0 animated:YES];
}
alertView = nil; alertView = nil;
} }
...@@ -564,7 +546,7 @@ ...@@ -564,7 +546,7 @@
_selectedAssets = selectedAssets; _selectedAssets = selectedAssets;
_selectedModels = [NSMutableArray array]; _selectedModels = [NSMutableArray array];
_selectedAssetIds = [NSMutableArray array]; _selectedAssetIds = [NSMutableArray array];
for (id asset in selectedAssets) { for (PHAsset *asset in selectedAssets) {
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:[[TZImageManager manager] getAssetType:asset]]; TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:[[TZImageManager manager] getAssetType:asset]];
model.isSelected = YES; model.isSelected = YES;
[self addSelectedModel:model]; [self addSelectedModel:model];
...@@ -609,9 +591,7 @@ ...@@ -609,9 +591,7 @@
} }
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (iOS7Later) {
viewController.automaticallyAdjustsScrollViewInsets = NO; viewController.automaticallyAdjustsScrollViewInsets = NO;
}
[super pushViewController:viewController animated:animated]; [super pushViewController:viewController animated:animated];
} }
...@@ -621,14 +601,12 @@ ...@@ -621,14 +601,12 @@
- (void)addSelectedModel:(TZAssetModel *)model { - (void)addSelectedModel:(TZAssetModel *)model {
[_selectedModels addObject:model]; [_selectedModels addObject:model];
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset]; [_selectedAssetIds addObject:model.asset.localIdentifier];
[_selectedAssetIds addObject:assetId];
} }
- (void)removeSelectedModel:(TZAssetModel *)model { - (void)removeSelectedModel:(TZAssetModel *)model {
[_selectedModels removeObject:model]; [_selectedModels removeObject:model];
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset]; [_selectedAssetIds removeObject:model.asset.localIdentifier];
[_selectedAssetIds removeObject:assetId];
} }
- (UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size radius:(CGFloat)radius { - (UIImage *)createImageWithColor:(UIColor *)color size:(CGSize)size radius:(CGFloat)radius {
...@@ -650,31 +628,18 @@ ...@@ -650,31 +628,18 @@
#pragma mark - UIContentContainer #pragma mark - UIContentContainer
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[self willInterfaceOrientionChange]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (size.width > size.height) { if (![UIApplication sharedApplication].statusBarHidden) {
_cropRect = _cropRectLandscape; if (self.needShowStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
} else {
_cropRect = _cropRectPortrait;
} }
} });
if (size.width > size.height) {
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self willInterfaceOrientionChange];
if (toInterfaceOrientation >= 3) {
_cropRect = _cropRectLandscape; _cropRect = _cropRectLandscape;
} else { } else {
_cropRect = _cropRectPortrait; _cropRect = _cropRectPortrait;
} }
} }
- (void)willInterfaceOrientionChange {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (![UIApplication sharedApplication].statusBarHidden) {
if (iOS7Later && self.needShowStatusBar) [UIApplication sharedApplication].statusBarHidden = NO;
}
});
}
#pragma mark - Layout #pragma mark - Layout
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
...@@ -799,7 +764,7 @@ ...@@ -799,7 +764,7 @@
BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden; BOOL isStatusBarHidden = [UIApplication sharedApplication].isStatusBarHidden;
if (self.navigationController.navigationBar.isTranslucent) { if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight; top = naviBarHeight;
if (iOS7Later && !isStatusBarHidden) top += [TZCommonTools tz_statusBarHeight]; if (!isStatusBarHidden) top += [TZCommonTools tz_statusBarHeight];
tableViewHeight = self.view.tz_height - top; tableViewHeight = self.view.tz_height - top;
} else { } else {
tableViewHeight = self.view.tz_height; tableViewHeight = self.view.tz_height;
...@@ -856,33 +821,6 @@ ...@@ -856,33 +821,6 @@
@end @end
@implementation NSString (TzExtension)
- (BOOL)tz_containsString:(NSString *)string {
if (iOS8Later) {
return [self containsString:string];
} else {
NSRange range = [self rangeOfString:string];
return range.location != NSNotFound;
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (CGSize)tz_calculateSizeWithAttributes:(NSDictionary *)attributes maxSize:(CGSize)maxSize {
CGSize size;
if (iOS7Later) {
size = [self boundingRectWithSize:maxSize options:NSStringDrawingUsesFontLeading attributes:attributes context:nil].size;
} else {
size = [self sizeWithFont:attributes[NSFontAttributeName] constrainedToSize:maxSize];
}
return size;
}
#pragma clang diagnostic pop
@end
@implementation TZCommonTools @implementation TZCommonTools
+ (BOOL)tz_isIPhoneX { + (BOOL)tz_isIPhoneX {
......
...@@ -28,9 +28,7 @@ ...@@ -28,9 +28,7 @@
manager = [[self alloc] init]; manager = [[self alloc] init];
manager.locationManager = [[CLLocationManager alloc] init]; manager.locationManager = [[CLLocationManager alloc] init];
manager.locationManager.delegate = manager; manager.locationManager.delegate = manager;
if (iOS8Later) {
[manager.locationManager requestWhenInUseAuthorization]; [manager.locationManager requestWhenInUseAuthorization];
}
}); });
return manager; return manager;
} }
......
...@@ -56,9 +56,7 @@ static CGFloat itemMargin = 5; ...@@ -56,9 +56,7 @@ static CGFloat itemMargin = 5;
_imagePickerVc = [[UIImagePickerController alloc] init]; _imagePickerVc = [[UIImagePickerController alloc] init];
_imagePickerVc.delegate = self; _imagePickerVc.delegate = self;
// set appearance / 改变相册选择页的导航栏外观 // set appearance / 改变相册选择页的导航栏外观
if (iOS7Later) {
_imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor; _imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
}
_imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor; _imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
UIBarButtonItem *tzBarItem, *BarItem; UIBarButtonItem *tzBarItem, *BarItem;
if (@available(iOS 9, *)) { if (@available(iOS 9, *)) {
...@@ -103,14 +101,14 @@ static CGFloat itemMargin = 5; ...@@ -103,14 +101,14 @@ static CGFloat itemMargin = 5;
[tzImagePickerVc showProgressHUD]; [tzImagePickerVc showProgressHUD];
} }
dispatch_async(dispatch_get_global_queue(0, 0), ^{ dispatch_async(dispatch_get_global_queue(0, 0), ^{
if (!tzImagePickerVc.sortAscendingByModificationDate && self->_isFirstAppear && iOS8Later && self->_model.isCameraRoll) { if (!tzImagePickerVc.sortAscendingByModificationDate && self->_isFirstAppear && self->_model.isCameraRoll) {
[[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage needFetchAssets:YES completion:^(TZAlbumModel *model) { [[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage needFetchAssets:YES completion:^(TZAlbumModel *model) {
self->_model = model; self->_model = model;
self->_models = [NSMutableArray arrayWithArray:self->_model.models]; self->_models = [NSMutableArray arrayWithArray:self->_model.models];
[self initSubviews]; [self initSubviews];
}]; }];
} else { } else {
if (self->_showTakePhotoBtn || !iOS8Later || self->_isFirstAppear) { if (self->_showTakePhotoBtn || self->_isFirstAppear) {
[[TZImageManager manager] getAssetsFromFetchResult:self->_model.result completion:^(NSArray<TZAssetModel *> *models) { [[TZImageManager manager] getAssetsFromFetchResult:self->_model.result completion:^(NSArray<TZAssetModel *> *models) {
self->_models = [NSMutableArray arrayWithArray:models]; self->_models = [NSMutableArray arrayWithArray:models];
[self initSubviews]; [self initSubviews];
...@@ -183,9 +181,7 @@ static CGFloat itemMargin = 5; ...@@ -183,9 +181,7 @@ static CGFloat itemMargin = 5;
- (void)viewDidAppear:(BOOL)animated { - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]; [super viewDidAppear:animated];
if (iOS8Later) {
// [self updateCachedAssets]; // [self updateCachedAssets];
}
} }
- (void)configBottomToolBar { - (void)configBottomToolBar {
...@@ -283,7 +279,7 @@ static CGFloat itemMargin = 5; ...@@ -283,7 +279,7 @@ static CGFloat itemMargin = 5;
CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 50 + (83 - 49) : 50; CGFloat toolBarHeight = [TZCommonTools tz_isIPhoneX] ? 50 + (83 - 49) : 50;
if (self.navigationController.navigationBar.isTranslucent) { if (self.navigationController.navigationBar.isTranslucent) {
top = naviBarHeight; top = naviBarHeight;
if (iOS7Later && !isStatusBarHidden) top += [TZCommonTools tz_statusBarHeight]; if (!isStatusBarHidden) top += [TZCommonTools tz_statusBarHeight];
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - toolBarHeight - top : self.view.tz_height - top;; collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - toolBarHeight - top : self.view.tz_height - top;;
} else { } else {
collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - toolBarHeight : self.view.tz_height; collectionViewHeight = tzImagePickerVc.showSelectBtn ? self.view.tz_height - toolBarHeight : self.view.tz_height;
...@@ -303,19 +299,19 @@ static CGFloat itemMargin = 5; ...@@ -303,19 +299,19 @@ static CGFloat itemMargin = 5;
if (!self.navigationController.navigationBar.isHidden) { if (!self.navigationController.navigationBar.isHidden) {
toolBarTop = self.view.tz_height - toolBarHeight; toolBarTop = self.view.tz_height - toolBarHeight;
} else { } else {
CGFloat navigationHeight = naviBarHeight; CGFloat navigationHeight = naviBarHeight + [TZCommonTools tz_statusBarHeight];
if (iOS7Later) navigationHeight += [TZCommonTools tz_statusBarHeight];
toolBarTop = self.view.tz_height - toolBarHeight - navigationHeight; toolBarTop = self.view.tz_height - toolBarHeight - navigationHeight;
} }
_bottomToolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight); _bottomToolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight);
CGFloat previewWidth = [tzImagePickerVc.previewBtnTitleStr tz_calculateSizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} maxSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)].width + 2;
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) { if (!tzImagePickerVc.allowPreview) {
previewWidth = 0.0; previewWidth = 0.0;
} }
_previewButton.frame = CGRectMake(10, 3, previewWidth, 44); _previewButton.frame = CGRectMake(10, 3, previewWidth, 44);
_previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth; _previewButton.tz_width = !tzImagePickerVc.showSelectBtn ? 0 : previewWidth;
if (tzImagePickerVc.allowPickingOriginalPhoto) { if (tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [tzImagePickerVc.fullImageBtnTitleStr tz_calculateSizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} maxSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)].width; 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), 0, fullImageWidth + 56, 50); _originalPhotoButton.frame = CGRectMake(CGRectGetMaxX(_previewButton.frame), 0, fullImageWidth + 56, 50);
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50); _originalPhotoLabel.frame = CGRectMake(fullImageWidth + 46, 0, 80, 50);
} }
...@@ -382,7 +378,7 @@ static CGFloat itemMargin = 5; ...@@ -382,7 +378,7 @@ static CGFloat itemMargin = 5;
__block BOOL havenotShowAlert = YES; __block BOOL havenotShowAlert = YES;
[TZImageManager manager].shouldFixOrientation = YES; [TZImageManager manager].shouldFixOrientation = YES;
__block id alertView; __block UIAlertController *alertView;
for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) { for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) {
TZAssetModel *model = tzImagePickerVc.selectedModels[i]; TZAssetModel *model = tzImagePickerVc.selectedModels[i];
[[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { [[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
...@@ -503,8 +499,7 @@ static CGFloat itemMargin = 5; ...@@ -503,8 +499,7 @@ static CGFloat itemMargin = 5;
cell.allowPickingGif = tzImagePickerVc.allowPickingGif; cell.allowPickingGif = tzImagePickerVc.allowPickingGif;
cell.model = model; cell.model = model;
if (model.isSelected && tzImagePickerVc.showSelectedIndex) { if (model.isSelected && tzImagePickerVc.showSelectedIndex) {
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset]; cell.index = [tzImagePickerVc.selectedAssetIds indexOfObject:model.asset.localIdentifier] + 1;
cell.index = [tzImagePickerVc.selectedAssetIds indexOfObject:assetId] + 1;
} }
cell.showSelectBtn = tzImagePickerVc.showSelectBtn; cell.showSelectBtn = tzImagePickerVc.showSelectBtn;
cell.allowPreview = tzImagePickerVc.allowPreview; cell.allowPreview = tzImagePickerVc.allowPreview;
...@@ -530,7 +525,7 @@ static CGFloat itemMargin = 5; ...@@ -530,7 +525,7 @@ static CGFloat itemMargin = 5;
model.isSelected = NO; model.isSelected = NO;
NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels]; NSArray *selectedModels = [NSArray arrayWithArray:tzImagePickerVc.selectedModels];
for (TZAssetModel *model_item in selectedModels) { for (TZAssetModel *model_item in selectedModels) {
if ([[[TZImageManager manager] getAssetIdentifier:model.asset] isEqualToString:[[TZImageManager manager] getAssetIdentifier:model_item.asset]]) { if ([model.asset.localIdentifier isEqualToString:model_item.asset.localIdentifier]) {
[tzImagePickerVc removeSelectedModel:model_item]; [tzImagePickerVc removeSelectedModel:model_item];
break; break;
} }
...@@ -608,9 +603,7 @@ static CGFloat itemMargin = 5; ...@@ -608,9 +603,7 @@ static CGFloat itemMargin = 5;
#pragma mark - UIScrollViewDelegate #pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (iOS8Later) {
// [self updateCachedAssets]; // [self updateCachedAssets];
}
} }
#pragma mark - Private Method #pragma mark - Private Method
...@@ -626,7 +619,7 @@ static CGFloat itemMargin = 5; ...@@ -626,7 +619,7 @@ static CGFloat itemMargin = 5;
/// 拍照按钮点击事件 /// 拍照按钮点击事件
- (void)takePhoto { - (void)takePhoto {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS7Later) { if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)) {
NSDictionary *infoDict = [TZCommonTools tz_getInfoDictionary]; NSDictionary *infoDict = [TZCommonTools tz_getInfoDictionary];
// 无权限 做一个友好的提示 // 无权限 做一个友好的提示
...@@ -634,16 +627,10 @@ static CGFloat itemMargin = 5; ...@@ -634,16 +627,10 @@ static CGFloat itemMargin = 5;
if (!appName) appName = [infoDict valueForKey:@"CFBundleName"]; if (!appName) appName = [infoDict valueForKey:@"CFBundleName"];
NSString *message = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Please allow %@ to access your camera in \"Settings -> Privacy -> Camera\""],appName]; NSString *message = [NSString stringWithFormat:[NSBundle tz_localizedStringForKey:@"Please allow %@ to access your camera in \"Settings -> Privacy -> Camera\""],appName];
if (iOS8Later) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Can not use camera"] message:message delegate:self cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"Cancel"] otherButtonTitles:[NSBundle tz_localizedStringForKey:@"Setting"], nil]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Can not use camera"] message:message delegate:self cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"Cancel"] otherButtonTitles:[NSBundle tz_localizedStringForKey:@"Setting"], nil];
[alert show]; [alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Can not use camera"] message:message delegate:self cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil];
[alert show];
}
} else if (authStatus == AVAuthorizationStatusNotDetermined) { } else if (authStatus == AVAuthorizationStatusNotDetermined) {
// fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏 // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
if (iOS7Later) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) { if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
...@@ -654,9 +641,6 @@ static CGFloat itemMargin = 5; ...@@ -654,9 +641,6 @@ static CGFloat itemMargin = 5;
} else { } else {
[self pushImagePickerController]; [self pushImagePickerController];
} }
} else {
[self pushImagePickerController];
}
} }
// 调用相机 // 调用相机
...@@ -686,9 +670,7 @@ static CGFloat itemMargin = 5; ...@@ -686,9 +670,7 @@ static CGFloat itemMargin = 5;
self.imagePickerVc.videoMaximumDuration = tzImagePickerVc.videoMaximumDuration; self.imagePickerVc.videoMaximumDuration = tzImagePickerVc.videoMaximumDuration;
} }
self.imagePickerVc.mediaTypes= mediaTypes; self.imagePickerVc.mediaTypes= mediaTypes;
if (iOS8Later) {
_imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext; _imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
if (tzImagePickerVc.uiImagePickerControllerSettingBlock) { if (tzImagePickerVc.uiImagePickerControllerSettingBlock) {
tzImagePickerVc.uiImagePickerControllerSettingBlock(_imagePickerVc); tzImagePickerVc.uiImagePickerControllerSettingBlock(_imagePickerVc);
} }
...@@ -781,7 +763,7 @@ static CGFloat itemMargin = 5; ...@@ -781,7 +763,7 @@ static CGFloat itemMargin = 5;
} }
for (TZAssetModel *model in _models) { for (TZAssetModel *model in _models) {
model.isSelected = NO; model.isSelected = NO;
if ([[TZImageManager manager] isAssetsArray:selectedAssets containAsset:model.asset]) { if ([selectedAssets containsObject:model.asset]) {
model.isSelected = YES; model.isSelected = YES;
} }
} }
...@@ -791,10 +773,8 @@ static CGFloat itemMargin = 5; ...@@ -791,10 +773,8 @@ static CGFloat itemMargin = 5;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) { // 去设置界面,开启相机访问权限 if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
if (iOS8Later) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
} }
}
} }
#pragma mark - UIImagePickerControllerDelegate #pragma mark - UIImagePickerControllerDelegate
......
...@@ -188,7 +188,7 @@ ...@@ -188,7 +188,7 @@
} }
} }
- (void)setAsset:(id)asset { - (void)setAsset:(PHAsset *)asset {
if (_asset && self.imageRequestID) { if (_asset && self.imageRequestID) {
[[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID]; [[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID];
} }
...@@ -412,7 +412,7 @@ ...@@ -412,7 +412,7 @@
if (currentTime.value == durationTime.value) [_player.currentItem seekToTime:CMTimeMake(0, 1)]; if (currentTime.value == durationTime.value) [_player.currentItem seekToTime:CMTimeMake(0, 1)];
[_player play]; [_player play];
[_playButton setImage:nil forState:UIControlStateNormal]; [_playButton setImage:nil forState:UIControlStateNormal];
if (iOS7Later) [UIApplication sharedApplication].statusBarHidden = YES; [UIApplication sharedApplication].statusBarHidden = YES;
if (self.singleTapGestureBlock) { if (self.singleTapGestureBlock) {
self.singleTapGestureBlock(); self.singleTapGestureBlock();
} }
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
@property (nonatomic, strong) UIView *cropView; @property (nonatomic, strong) UIView *cropView;
@property (nonatomic, assign) double progress; @property (nonatomic, assign) double progress;
@property (strong, nonatomic) id alertView; @property (strong, nonatomic) UIAlertController *alertView;
@end @end
@implementation TZPhotoPreviewController @implementation TZPhotoPreviewController
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES]; [self.navigationController setNavigationBarHidden:YES animated:YES];
if (iOS7Later) [UIApplication sharedApplication].statusBarHidden = YES; [UIApplication sharedApplication].statusBarHidden = YES;
if (_currentIndex) [_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * _currentIndex, 0) animated:NO]; if (_currentIndex) [_collectionView setContentOffset:CGPointMake((self.view.tz_width + 20) * _currentIndex, 0) animated:NO];
[self refreshNaviBarAndBottomBarState]; [self refreshNaviBarAndBottomBarState];
} }
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES]; [self.navigationController setNavigationBarHidden:NO animated:YES];
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (tzImagePickerVc.needShowStatusBar && iOS7Later) { if (tzImagePickerVc.needShowStatusBar) {
[UIApplication sharedApplication].statusBarHidden = NO; [UIApplication sharedApplication].statusBarHidden = NO;
} }
[TZImageManager manager].shouldFixOrientation = NO; [TZImageManager manager].shouldFixOrientation = NO;
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
CGFloat toolBarTop = self.view.tz_height - toolBarHeight; CGFloat toolBarTop = self.view.tz_height - toolBarHeight;
_toolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight); _toolBar.frame = CGRectMake(0, toolBarTop, self.view.tz_width, toolBarHeight);
if (_tzImagePickerVc.allowPickingOriginalPhoto) { if (_tzImagePickerVc.allowPickingOriginalPhoto) {
CGFloat fullImageWidth = [_tzImagePickerVc.fullImageBtnTitleStr tz_calculateSizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} maxSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)].width; 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); _originalPhotoButton.frame = CGRectMake(0, 0, fullImageWidth + 56, 44);
_originalPhotoLabel.frame = CGRectMake(fullImageWidth + 42, 0, 80, 44); _originalPhotoLabel.frame = CGRectMake(fullImageWidth + 42, 0, 80, 44);
} }
...@@ -315,7 +315,7 @@ ...@@ -315,7 +315,7 @@
} else { } else {
NSArray *selectedModels = [NSArray arrayWithArray:_tzImagePickerVc.selectedModels]; NSArray *selectedModels = [NSArray arrayWithArray:_tzImagePickerVc.selectedModels];
for (TZAssetModel *model_item in selectedModels) { for (TZAssetModel *model_item in selectedModels) {
if ([[[TZImageManager manager] getAssetIdentifier:model.asset] isEqualToString:[[TZImageManager manager] getAssetIdentifier:model_item.asset]]) { if ([model.asset.localIdentifier isEqualToString:model_item.asset.localIdentifier]) {
// 1.6.7版本更新:防止有多个一样的model,一次性被移除了 // 1.6.7版本更新:防止有多个一样的model,一次性被移除了
NSArray *selectedModelsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedModels]; NSArray *selectedModelsTmp = [NSArray arrayWithArray:_tzImagePickerVc.selectedModels];
for (NSInteger i = 0; i < selectedModelsTmp.count; i++) { for (NSInteger i = 0; i < selectedModelsTmp.count; i++) {
...@@ -513,8 +513,7 @@ ...@@ -513,8 +513,7 @@
_selectButton.selected = model.isSelected; _selectButton.selected = model.isSelected;
[self refreshSelectButtonImageViewContentMode]; [self refreshSelectButtonImageViewContentMode];
if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex && _tzImagePickerVc.showSelectBtn) { if (_selectButton.isSelected && _tzImagePickerVc.showSelectedIndex && _tzImagePickerVc.showSelectBtn) {
NSString *assetId = [[TZImageManager manager] getAssetIdentifier:model.asset]; NSString *index = [NSString stringWithFormat:@"%zd", [_tzImagePickerVc.selectedAssetIds indexOfObject:model.asset.localIdentifier] + 1];
NSString *index = [NSString stringWithFormat:@"%zd", [_tzImagePickerVc.selectedAssetIds indexOfObject:assetId] + 1];
_indexLabel.text = index; _indexLabel.text = index;
_indexLabel.hidden = NO; _indexLabel.hidden = NO;
} else { } else {
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
_originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; _originStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
[UIApplication sharedApplication].statusBarStyle = iOS7Later ? UIStatusBarStyleLightContent : UIStatusBarStyleBlackOpaque; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
} }
- (void)viewWillDisappear:(BOOL)animated { - (void)viewWillDisappear:(BOOL)animated {
...@@ -157,7 +157,7 @@ ...@@ -157,7 +157,7 @@
[self.navigationController setNavigationBarHidden:YES]; [self.navigationController setNavigationBarHidden:YES];
_toolBar.hidden = YES; _toolBar.hidden = YES;
[_playButton setImage:nil forState:UIControlStateNormal]; [_playButton setImage:nil forState:UIControlStateNormal];
if (iOS7Later) [UIApplication sharedApplication].statusBarHidden = YES; [UIApplication sharedApplication].statusBarHidden = YES;
} else { } else {
[self pausePlayerAndShowNaviBar]; [self pausePlayerAndShowNaviBar];
} }
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
[self.navigationController setNavigationBarHidden:NO]; [self.navigationController setNavigationBarHidden:NO];
[_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal]; [_playButton setImage:[UIImage imageNamedFromMyBundle:@"MMVideoPreviewPlay"] forState:UIControlStateNormal];
if (self.needShowStatusBar && iOS7Later) { if (self.needShowStatusBar) {
[UIApplication sharedApplication].statusBarHidden = NO; [UIApplication sharedApplication].statusBarHidden = NO;
} }
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#import "TZTestCell.h" #import "TZTestCell.h"
#import "UIView+Layout.h" #import "UIView+Layout.h"
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import "TZImagePickerController/TZImagePickerController.h" #import "TZImagePickerController/TZImagePickerController.h"
@implementation TZTestCell @implementation TZTestCell
...@@ -56,18 +55,11 @@ ...@@ -56,18 +55,11 @@
_videoImageView.frame = CGRectMake(width, width, width, width); _videoImageView.frame = CGRectMake(width, width, width, width);
} }
- (void)setAsset:(id)asset { - (void)setAsset:(PHAsset *)asset {
_asset = asset; _asset = asset;
if ([asset isKindOfClass:[PHAsset class]]) { _videoImageView.hidden = asset.mediaType != PHAssetMediaTypeVideo;
PHAsset *phAsset = asset; _gifLable.hidden = ![[asset valueForKey:@"filename"] containsString:@"GIF"];
_videoImageView.hidden = phAsset.mediaType != PHAssetMediaTypeVideo; }
_gifLable.hidden = ![[phAsset valueForKey:@"filename"] tz_containsString:@"GIF"];
} else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = asset;
_videoImageView.hidden = ![[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
_gifLable.hidden = YES;
}
}
- (void)setRow:(NSInteger)row { - (void)setRow:(NSInteger)row {
_row = row; _row = row;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#import "TZImagePickerController.h" #import "TZImagePickerController.h"
#import "UIView+Layout.h" #import "UIView+Layout.h"
#import "TZTestCell.h" #import "TZTestCell.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import "LxGridViewFlowLayout.h" #import "LxGridViewFlowLayout.h"
#import "TZImageManager.h" #import "TZImageManager.h"
...@@ -61,9 +60,7 @@ ...@@ -61,9 +60,7 @@
_imagePickerVc = [[UIImagePickerController alloc] init]; _imagePickerVc = [[UIImagePickerController alloc] init];
_imagePickerVc.delegate = self; _imagePickerVc.delegate = self;
// set appearance / 改变相册选择页的导航栏外观 // set appearance / 改变相册选择页的导航栏外观
if (iOS7Later) {
_imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor; _imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
}
_imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor; _imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
UIBarButtonItem *tzBarItem, *BarItem; UIBarButtonItem *tzBarItem, *BarItem;
if (@available(iOS 9, *)) { if (@available(iOS 9, *)) {
...@@ -193,16 +190,10 @@ ...@@ -193,16 +190,10 @@
[self pushTZImagePickerController]; [self pushTZImagePickerController];
} }
} else { // preview photos or video / 预览照片或者视频 } else { // preview photos or video / 预览照片或者视频
id asset = _selectedAssets[indexPath.item]; PHAsset *asset = _selectedAssets[indexPath.item];
BOOL isVideo = NO; BOOL isVideo = NO;
if ([asset isKindOfClass:[PHAsset class]]) { isVideo = asset.mediaType == PHAssetMediaTypeVideo;
PHAsset *phAsset = asset; if ([[asset valueForKey:@"filename"] containsString:@"GIF"] && self.allowPickingGifSwitch.isOn && !self.allowPickingMuitlpleVideoSwitch.isOn) {
isVideo = phAsset.mediaType == PHAssetMediaTypeVideo;
} else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = asset;
isVideo = [[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
}
if ([[asset valueForKey:@"filename"] tz_containsString:@"GIF"] && self.allowPickingGifSwitch.isOn && !self.allowPickingMuitlpleVideoSwitch.isOn) {
TZGifPhotoPreviewController *vc = [[TZGifPhotoPreviewController alloc] init]; TZGifPhotoPreviewController *vc = [[TZGifPhotoPreviewController alloc] init];
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:TZAssetModelMediaTypePhotoGif timeLength:@""]; TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:TZAssetModelMediaTypePhotoGif timeLength:@""];
vc.model = model; vc.model = model;
...@@ -282,9 +273,7 @@ ...@@ -282,9 +273,7 @@
// 2. Set the appearance // 2. Set the appearance
// 2. 在这里设置imagePickerVc的外观 // 2. 在这里设置imagePickerVc的外观
// if (iOS7Later) {
// imagePickerVc.navigationBar.barTintColor = [UIColor greenColor]; // imagePickerVc.navigationBar.barTintColor = [UIColor greenColor];
// }
// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor]; // imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
// imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor]; // imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];
// imagePickerVc.navigationBar.translucent = NO; // imagePickerVc.navigationBar.translucent = NO;
...@@ -385,18 +374,12 @@ ...@@ -385,18 +374,12 @@
- (void)takePhoto { - (void)takePhoto {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) { if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
// 无相机权限 做一个友好的提示 // 无相机权限 做一个友好的提示
if (iOS8Later) {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
[alert show]; [alert show];
} else {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}
} else if (authStatus == AVAuthorizationStatusNotDetermined) { } else if (authStatus == AVAuthorizationStatusNotDetermined) {
// fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏 // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
if (iOS7Later) {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) { if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
...@@ -404,18 +387,10 @@ ...@@ -404,18 +387,10 @@
}); });
} }
}]; }];
} else {
[self takePhoto];
}
// 拍照之前还需要检查相册权限 // 拍照之前还需要检查相册权限
} else if ([TZImageManager authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片 } else if ([TZImageManager authorizationStatus] == 2) { // 已被拒绝,没有相册权限,将无法保存拍的照片
if (iOS8Later) {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil]; UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
[alert show]; [alert show];
} else {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alert show];
}
} else if ([TZImageManager authorizationStatus] == 0) { // 未请求过相册权限 } else if ([TZImageManager authorizationStatus] == 0) { // 未请求过相册权限
[[TZImageManager manager] requestAuthorizationWithCompletion:^{ [[TZImageManager manager] requestAuthorizationWithCompletion:^{
[self takePhoto]; [self takePhoto];
...@@ -450,9 +425,7 @@ ...@@ -450,9 +425,7 @@
if (mediaTypes.count) { if (mediaTypes.count) {
_imagePickerVc.mediaTypes = mediaTypes; _imagePickerVc.mediaTypes = mediaTypes;
} }
if (iOS8Later) {
_imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext; _imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
[self presentViewController:_imagePickerVc animated:YES completion:nil]; [self presentViewController:_imagePickerVc animated:YES completion:nil];
} else { } else {
NSLog(@"模拟器中无法打开照相机,请在真机中使用"); NSLog(@"模拟器中无法打开照相机,请在真机中使用");
...@@ -523,7 +496,7 @@ ...@@ -523,7 +496,7 @@
} }
} }
- (void)refreshCollectionViewWithAddedAsset:(id)asset image:(UIImage *)image { - (void)refreshCollectionViewWithAddedAsset:(PHAsset *)asset image:(UIImage *)image {
[_selectedAssets addObject:asset]; [_selectedAssets addObject:asset];
[_selectedPhotos addObject:image]; [_selectedPhotos addObject:image];
[_collectionView reloadData]; [_collectionView reloadData];
...@@ -544,10 +517,8 @@ ...@@ -544,10 +517,8 @@
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) { // 去设置界面,开启相机访问权限 if (buttonIndex == 1) { // 去设置界面,开启相机访问权限
if (iOS8Later) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
} }
}
} }
#pragma mark - TZImagePickerControllerDelegate #pragma mark - TZImagePickerControllerDelegate
...@@ -576,11 +547,9 @@ ...@@ -576,11 +547,9 @@
// 1.打印图片名字 // 1.打印图片名字
[self printAssetsName:assets]; [self printAssetsName:assets];
// 2.图片位置信息 // 2.图片位置信息
if (iOS8Later) {
for (PHAsset *phAsset in assets) { for (PHAsset *phAsset in assets) {
NSLog(@"location:%@",phAsset.location); NSLog(@"location:%@",phAsset.location);
} }
}
/* /*
// 3. 获取原图的示例,这样一次性获取很可能会导致内存飙升,建议获取1-2张,消费和释放掉,再获取剩下的 // 3. 获取原图的示例,这样一次性获取很可能会导致内存飙升,建议获取1-2张,消费和释放掉,再获取剩下的
...@@ -603,10 +572,8 @@ ...@@ -603,10 +572,8 @@
} }
// If user picking a video, this callback will be called. // If user picking a video, this callback will be called.
// If system version > iOS8,asset is kind of PHAsset class, else is ALAsset class.
// 如果用户选择了一个视频,下面的handle会被执行 // 如果用户选择了一个视频,下面的handle会被执行
// 如果系统版本大于iOS8,asset是PHAsset类的对象,否则是ALAsset类的对象 - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(PHAsset *)asset {
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset {
_selectedPhotos = [NSMutableArray arrayWithArray:@[coverImage]]; _selectedPhotos = [NSMutableArray arrayWithArray:@[coverImage]];
_selectedAssets = [NSMutableArray arrayWithArray:@[asset]]; _selectedAssets = [NSMutableArray arrayWithArray:@[asset]];
// open this code to send video / 打开这段代码发送视频 // open this code to send video / 打开这段代码发送视频
...@@ -623,7 +590,7 @@ ...@@ -623,7 +590,7 @@
// If user picking a gif image, this callback will be called. // If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行 // 如果用户选择了一个gif图片,下面的handle会被执行
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset { - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(PHAsset *)asset {
_selectedPhotos = [NSMutableArray arrayWithArray:@[animatedImage]]; _selectedPhotos = [NSMutableArray arrayWithArray:@[animatedImage]];
_selectedAssets = [NSMutableArray arrayWithArray:@[asset]]; _selectedAssets = [NSMutableArray arrayWithArray:@[asset]];
[_collectionView reloadData]; [_collectionView reloadData];
...@@ -631,7 +598,7 @@ ...@@ -631,7 +598,7 @@
// Decide album show or not't // Decide album show or not't
// 决定相册显示与否 // 决定相册显示与否
- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result { - (BOOL)isAlbumCanSelect:(NSString *)albumName result:(PHFetchResult *)result {
/* /*
if ([albumName isEqualToString:@"个人收藏"]) { if ([albumName isEqualToString:@"个人收藏"]) {
return NO; return NO;
...@@ -644,11 +611,9 @@ ...@@ -644,11 +611,9 @@
// Decide asset show or not't // Decide asset show or not't
// 决定asset显示与否 // 决定asset显示与否
- (BOOL)isAssetCanSelect:(id)asset { - (BOOL)isAssetCanSelect:(PHAsset *)asset {
/* /*
if (iOS8Later) { switch (asset.mediaType) {
PHAsset *phAsset = asset;
switch (phAsset.mediaType) {
case PHAssetMediaTypeVideo: { case PHAssetMediaTypeVideo: {
// 视频时长 // 视频时长
// NSTimeInterval duration = phAsset.duration; // NSTimeInterval duration = phAsset.duration;
...@@ -669,24 +634,7 @@ ...@@ -669,24 +634,7 @@
break; break;
default: break; default: break;
} }
} else { */
ALAsset *alAsset = asset;
NSString *alAssetType = [[alAsset valueForProperty:ALAssetPropertyType] stringValue];
if ([alAssetType isEqualToString:ALAssetTypeVideo]) {
// 视频时长
// NSTimeInterval duration = [[alAsset valueForProperty:ALAssetPropertyDuration] doubleValue];
return NO;
} else if ([alAssetType isEqualToString:ALAssetTypePhoto]) {
// 图片尺寸
CGSize imageSize = alAsset.defaultRepresentation.dimensions;
if (imageSize.width > 3000) {
// return NO;
}
return YES;
} else if ([alAssetType isEqualToString:ALAssetTypeUnknown]) {
return NO;
}
}*/
return YES; return YES;
} }
...@@ -794,14 +742,8 @@ ...@@ -794,14 +742,8 @@
/// 打印图片名字 /// 打印图片名字
- (void)printAssetsName:(NSArray *)assets { - (void)printAssetsName:(NSArray *)assets {
NSString *fileName; NSString *fileName;
for (id asset in assets) { for (PHAsset *asset in assets) {
if ([asset isKindOfClass:[PHAsset class]]) { fileName = [asset valueForKey:@"filename"];
PHAsset *phAsset = (PHAsset *)asset;
fileName = [phAsset valueForKey:@"filename"];
} else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = (ALAsset *)asset;
fileName = alAsset.defaultRepresentation.filename;;
}
// NSLog(@"图片名字:%@",fileName); // NSLog(@"图片名字:%@",fileName);
} }
} }
......
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