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

移除iOS6和7的适配代码

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