Commit 78c77359 authored by tanzhen's avatar tanzhen

修复iOS6和7系统下照片显示方向的问题;修复第一次访问相册得到授权后没立即加载图片的问题。优化iOS6和7图片预览体验,先返回缩略图,再返回全屏图

parent a26f1d22
...@@ -9,6 +9,6 @@ Pod::Spec.new do |s| ...@@ -9,6 +9,6 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "6.0" s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.0.4" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.0.4" }
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/Resourse/*.{png,xib,nib}" s.resources = "TZImagePickerController/TZImagePickerController/Resource/*.{png,xib,nib}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
end end
\ No newline at end of file
...@@ -552,11 +552,13 @@ ...@@ -552,11 +552,13 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TZImagePickerController/Info.plist; INFOPLIST_FILE = TZImagePickerController/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0; IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePickerController; PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePickerController;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
}; };
name = Debug; name = Debug;
}; };
...@@ -565,11 +567,13 @@ ...@@ -565,11 +567,13 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TZImagePickerController/Info.plist; INFOPLIST_FILE = TZImagePickerController/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0; IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePickerController; PRODUCT_BUNDLE_IDENTIFIER = tanzhen.TZImagePickerController;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
}; };
name = Release; name = Release;
}; };
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIMainStoryboardFile</key> <key>UIMainStoryboardFile</key>
<string>Main</string> <string>Main</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIRequiredDeviceCapabilities</key> <key>UIRequiredDeviceCapabilities</key>
<array> <array>
<string>armv7</string> <string>armv7</string>
...@@ -38,5 +36,7 @@ ...@@ -38,5 +36,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict> </dict>
</plist> </plist>
...@@ -108,11 +108,11 @@ ...@@ -108,11 +108,11 @@
[albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]]; [albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]];
} }
} }
if (completion) completion(albumArr); if (completion && albumArr.count > 0) completion(albumArr);
} else { } else {
[self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { [self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group == nil) { if (group == nil) {
if (completion) completion(albumArr); if (completion && albumArr.count > 0) completion(albumArr);
} }
if ([group numberOfAssets] < 1) return; if ([group numberOfAssets] < 1) return;
NSString *name = [group valueForProperty:ALAssetsGroupPropertyName]; NSString *name = [group valueForProperty:ALAssetsGroupPropertyName];
...@@ -133,17 +133,21 @@ ...@@ -133,17 +133,21 @@
- (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *))completion { - (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *))completion {
NSMutableArray *photoArr = [NSMutableArray array]; NSMutableArray *photoArr = [NSMutableArray array];
if ([result isKindOfClass:[PHFetchResult class]]) { if ([result isKindOfClass:[PHFetchResult class]]) {
for (PHAsset *asset in result) { PHFetchResult *fetchResult = (PHFetchResult *)result;
[fetchResult enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
PHAsset *asset = (PHAsset *)obj;
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto; TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if (asset.mediaType == PHAssetMediaTypeVideo) type = TZAssetModelMediaTypeVideo; if (asset.mediaType == PHAssetMediaTypeVideo) type = TZAssetModelMediaTypeVideo;
else if (asset.mediaType == PHAssetMediaTypeAudio) type = TZAssetModelMediaTypeAudio; else if (asset.mediaType == PHAssetMediaTypeAudio) type = TZAssetModelMediaTypeAudio;
else if (asset.mediaType == PHAssetMediaTypeImage) { else if (asset.mediaType == PHAssetMediaTypeImage) {
if (asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) type = TZAssetModelMediaTypeLivePhoto; if (iOS9_1Later) {
// if (asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) type = TZAssetModelMediaTypeLivePhoto;
}
} }
NSString *timeLength = type == TZAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",asset.duration] : @""; NSString *timeLength = type == TZAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",asset.duration] : @"";
timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue]; timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];
[photoArr addObject:[TZAssetModel modelWithAsset:asset type:type timeLength:timeLength]]; [photoArr addObject:[TZAssetModel modelWithAsset:asset type:type timeLength:timeLength]];
} }];
if (completion) completion(photoArr); if (completion) completion(photoArr);
} else if ([result isKindOfClass:[ALAssetsGroup class]]) { } else if ([result isKindOfClass:[ALAssetsGroup class]]) {
ALAssetsGroup *gruop = (ALAssetsGroup *)result; ALAssetsGroup *gruop = (ALAssetsGroup *)result;
...@@ -248,14 +252,20 @@ ...@@ -248,14 +252,20 @@
} else if ([asset isKindOfClass:[ALAsset class]]) { } else if ([asset isKindOfClass:[ALAsset class]]) {
ALAsset *alAsset = (ALAsset *)asset; ALAsset *alAsset = (ALAsset *)asset;
ALAssetRepresentation *assetRep = [alAsset defaultRepresentation]; ALAssetRepresentation *assetRep = [alAsset defaultRepresentation];
CGImageRef imageRef; CGImageRef thumbnailImageRef = alAsset.aspectRatioThumbnail;
UIImage *thumbnailImage = [UIImage imageWithCGImage:thumbnailImageRef scale:1.0 orientation:UIImageOrientationUp];
if (completion) completion(thumbnailImage,nil,YES);
if (photoWidth == [UIScreen mainScreen].bounds.size.width) { if (photoWidth == [UIScreen mainScreen].bounds.size.width) {
imageRef = [assetRep fullScreenImage]; dispatch_async(dispatch_get_global_queue(0,0), ^{
} else { CGImageRef fullScrennImageRef = [assetRep fullScreenImage];
imageRef = alAsset.thumbnail; UIImage *fullScrennImage = [UIImage imageWithCGImage:fullScrennImageRef scale:1.0 orientation:UIImageOrientationUp];
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(fullScrennImage,nil,NO);
});
});
} }
UIImage *image = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:(UIImageOrientation)[assetRep orientation]];
if (completion) completion(image,nil,NO);
} }
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f) #define iOS7Later ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f)
#define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f) #define iOS8Later ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f)
#define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f) #define iOS9Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.0f)
#define iOS9_1Later ([UIDevice currentDevice].systemVersion.floatValue >= 9.1f)
@protocol TZImagePickerControllerDelegate; @protocol TZImagePickerControllerDelegate;
@interface TZImagePickerController : UINavigationController @interface TZImagePickerController : UINavigationController
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#import "TZImageManager.h" #import "TZImageManager.h"
@interface TZImagePickerController () { @interface TZImagePickerController () {
NSTimer *_timer;
UILabel *_tipLable;
BOOL _pushToPhotoPickerVc; BOOL _pushToPhotoPickerVc;
UIButton *_progressHUD; UIButton *_progressHUD;
...@@ -28,6 +30,7 @@ ...@@ -28,6 +30,7 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationBar.barStyle = UIBarStyleBlack; self.navigationBar.barStyle = UIBarStyleBlack;
self.navigationBar.translucent = YES; self.navigationBar.translucent = YES;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
...@@ -63,17 +66,34 @@ ...@@ -63,17 +66,34 @@
_allowPickingVideo = YES; _allowPickingVideo = YES;
if (![[TZImageManager manager] authorizationStatusAuthorized]) { if (![[TZImageManager manager] authorizationStatusAuthorized]) {
UILabel *tipLable = [[UILabel alloc] init]; _tipLable = [[UILabel alloc] init];
tipLable.frame = CGRectMake(8, 0, self.view.width - 16, 300); _tipLable.frame = CGRectMake(8, 0, self.view.width - 16, 300);
tipLable.textAlignment = NSTextAlignmentCenter; _tipLable.textAlignment = NSTextAlignmentCenter;
tipLable.numberOfLines = 0; _tipLable.numberOfLines = 0;
tipLable.font = [UIFont systemFontOfSize:16]; _tipLable.font = [UIFont systemFontOfSize:16];
tipLable.textColor = [UIColor blackColor]; _tipLable.textColor = [UIColor blackColor];
NSString *appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"]; NSString *appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleDisplayName"];
if (!appName) appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleName"]; if (!appName) appName = [[NSBundle mainBundle].infoDictionary valueForKey:@"CFBundleName"];
tipLable.text = [NSString stringWithFormat:@"请在%@的\"设置-隐私-照片\"选项中,\r允许%@访问你的手机相册。",[UIDevice currentDevice].model,appName]; _tipLable.text = [NSString stringWithFormat:@"请在%@的\"设置-隐私-照片\"选项中,\r允许%@访问你的手机相册。",[UIDevice currentDevice].model,appName];
[self.view addSubview:tipLable]; [self.view addSubview:_tipLable];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(observeAuthrizationStatusChange) userInfo:nil repeats:YES];
} else { } else {
[self pushToPhotoPickerVc];
}
}
return self;
}
- (void)observeAuthrizationStatusChange {
if ([[TZImageManager manager] authorizationStatusAuthorized]) {
[self pushToPhotoPickerVc];
[_tipLable removeFromSuperview];
[_timer invalidate];
}
}
- (void)pushToPhotoPickerVc {
_pushToPhotoPickerVc = YES; _pushToPhotoPickerVc = YES;
if (_pushToPhotoPickerVc) { if (_pushToPhotoPickerVc) {
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init]; TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
...@@ -83,9 +103,6 @@ ...@@ -83,9 +103,6 @@
_pushToPhotoPickerVc = NO; _pushToPhotoPickerVc = NO;
}]; }];
} }
}
}
return self;
} }
- (void)showAlertWithTitle:(NSString *)title { - (void)showAlertWithTitle:(NSString *)title {
...@@ -164,16 +181,23 @@ ...@@ -164,16 +181,23 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = @"照片"; self.navigationItem.title = @"照片";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[[TZImageManager manager] getAllAlbums:imagePickerVc.allowPickingVideo completion:^(NSArray<TZAlbumModel *> *models) {
_albumArr = [NSMutableArray arrayWithArray:models];
[self configTableView]; [self configTableView];
}]; }
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (_albumArr) return;
[self configTableView];
} }
- (void)configTableView { - (void)configTableView {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[[TZImageManager manager] getAllAlbums:imagePickerVc.allowPickingVideo completion:^(NSArray<TZAlbumModel *> *models) {
_albumArr = [NSMutableArray arrayWithArray:models];
CGFloat top = 44; CGFloat top = 44;
if (iOS7Later) top += 20; if (iOS7Later) top += 20;
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, top, self.view.width, self.view.height - top) style:UITableViewStylePlain]; _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, top, self.view.width, self.view.height - top) style:UITableViewStylePlain];
...@@ -183,6 +207,7 @@ ...@@ -183,6 +207,7 @@
_tableView.delegate = self; _tableView.delegate = self;
[_tableView registerNib:[UINib nibWithNibName:@"TZAlbumCell" bundle:nil] forCellReuseIdentifier:@"TZAlbumCell"]; [_tableView registerNib:[UINib nibWithNibName:@"TZAlbumCell" bundle:nil] forCellReuseIdentifier:@"TZAlbumCell"];
[self.view addSubview:_tableView]; [self.view addSubview:_tableView];
}];
} }
#pragma mark - Click Event #pragma mark - Click Event
......
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