Commit 6950bfde authored by banchichen's avatar banchichen

修复内存泄露的问题;修复iOS7下拍照的几个问题等

parent ea468ff9
File added
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "TZImagePickerController" s.name = "TZImagePickerController"
s.version = "1.3.1" s.version = "1.3.3"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video" s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController" s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT" s.license = "MIT"
s.author = { "banchichen" => "736420282@qq.com" } s.author = { "banchichen" => "736420282@qq.com" }
s.platform = :ios s.platform = :ios
s.ios.deployment_target = "6.0" s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.3.1" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.3.3" }
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}" s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
- (void)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (void)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion; - (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
/// Save photo 保存照片
- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)())completion;
/// Get video 获得视频 /// Get video 获得视频
- (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion; - (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion;
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
} }
} else { } else {
[self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { [self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([group numberOfAssets] < 1) return; if ([group numberOfAssets] < 1) return;
NSString *name = [group valueForProperty:ALAssetsGroupPropertyName]; NSString *name = [group valueForProperty:ALAssetsGroupPropertyName];
if ([name isEqualToString:@"Camera Roll"] || [name isEqualToString:@"相机胶卷"] || [name isEqualToString:@"所有照片"]) { if ([name isEqualToString:@"Camera Roll"] || [name isEqualToString:@"相机胶卷"] || [name isEqualToString:@"所有照片"]) {
...@@ -159,8 +158,13 @@ ...@@ -159,8 +158,13 @@
if (completion) completion(photoArr); if (completion) completion(photoArr);
} else if ([result isKindOfClass:[ALAssetsGroup class]]) { } else if ([result isKindOfClass:[ALAssetsGroup class]]) {
ALAssetsGroup *group = (ALAssetsGroup *)result; ALAssetsGroup *group = (ALAssetsGroup *)result;
if (!allowPickingVideo) [group setAssetsFilter:[ALAssetsFilter allPhotos]]; if (allowPickingImage && allowPickingVideo) {
if (!allowPickingImage) [group setAssetsFilter:[ALAssetsFilter allPhotos]]; [group setAssetsFilter:[ALAssetsFilter allAssets]];
} else if (allowPickingVideo) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
} else if (allowPickingImage) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
}
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result == nil) { if (result == nil) {
if (completion) completion(photoArr); if (completion) completion(photoArr);
...@@ -170,11 +174,6 @@ ...@@ -170,11 +174,6 @@
[photoArr addObject:[TZAssetModel modelWithAsset:result type:type]]; [photoArr addObject:[TZAssetModel modelWithAsset:result type:type]];
return; return;
} }
if (!allowPickingImage){
[photoArr addObject:[TZAssetModel modelWithAsset:result type:type]];
return;
}
/// Allow picking video /// Allow picking video
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
type = TZAssetModelMediaTypeVideo; type = TZAssetModelMediaTypeVideo;
...@@ -209,8 +208,13 @@ ...@@ -209,8 +208,13 @@
if (completion) completion(model); if (completion) completion(model);
} else if ([result isKindOfClass:[ALAssetsGroup class]]) { } else if ([result isKindOfClass:[ALAssetsGroup class]]) {
ALAssetsGroup *group = (ALAssetsGroup *)result; ALAssetsGroup *group = (ALAssetsGroup *)result;
if (!allowPickingVideo) [group setAssetsFilter:[ALAssetsFilter allPhotos]]; if (allowPickingImage && allowPickingVideo) {
if (!allowPickingImage) [group setAssetsFilter:[ALAssetsFilter allVideos]]; [group setAssetsFilter:[ALAssetsFilter allAssets]];
} else if (allowPickingVideo) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
} else if (allowPickingImage) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
}
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index]; NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
[group enumerateAssetsAtIndexes:indexSet options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { [group enumerateAssetsAtIndexes:indexSet options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
TZAssetModel *model; TZAssetModel *model;
...@@ -220,12 +224,6 @@ ...@@ -220,12 +224,6 @@
if (completion) completion(model); if (completion) completion(model);
return; return;
} }
if (!allowPickingImage){
model = [TZAssetModel modelWithAsset:result type:type];
if (completion) completion(model);
return;
}
/// Allow picking video /// Allow picking video
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
type = TZAssetModelMediaTypeVideo; type = TZAssetModelMediaTypeVideo;
...@@ -392,6 +390,35 @@ ...@@ -392,6 +390,35 @@
} }
} }
#pragma mark - Save photo
- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)())completion {
NSData *data = UIImageJPEGRepresentation(image, 0.9);
if (iOS8Later) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:nil];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
dispatch_sync(dispatch_get_main_queue(), ^{
if (success && completion) {
completion();
} else if (error) {
NSLog(@"保存照片出错:%@",error.localizedDescription);
}
});
}];
} else {
[self.assetLibrary writeImageToSavedPhotosAlbum:image.CGImage orientation:ALAssetOrientationUp completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"保存图片失败:%@",error.localizedDescription);
} else {
if (completion) {
completion();
}
}
}];
}
}
#pragma mark - Get Video #pragma mark - Get Video
- (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * _Nullable, NSDictionary * _Nullable))completion { - (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * _Nullable, NSDictionary * _Nullable))completion {
......
...@@ -235,9 +235,8 @@ ...@@ -235,9 +235,8 @@
@interface TZAlbumPickerController ()<UITableViewDataSource,UITableViewDelegate> { @interface TZAlbumPickerController ()<UITableViewDataSource,UITableViewDelegate> {
UITableView *_tableView; UITableView *_tableView;
NSMutableArray *_albumArr;
} }
@property (nonatomic, strong) NSMutableArray *albumArr;
@end @end
@implementation TZAlbumPickerController @implementation TZAlbumPickerController
...@@ -319,8 +318,9 @@ ...@@ -319,8 +318,9 @@
TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init]; TZPhotoPickerController *photoPickerVc = [[TZPhotoPickerController alloc] init];
TZAlbumModel *model = _albumArr[indexPath.row]; TZAlbumModel *model = _albumArr[indexPath.row];
photoPickerVc.model = model; photoPickerVc.model = model;
__weak typeof(self) weakSelf = self;
[photoPickerVc setBackButtonClickHandle:^(TZAlbumModel *model) { [photoPickerVc setBackButtonClickHandle:^(TZAlbumModel *model) {
[_albumArr replaceObjectAtIndex:indexPath.row withObject:model]; [weakSelf.albumArr replaceObjectAtIndex:indexPath.row withObject:model];
}]; }];
[self.navigationController pushViewController:photoPickerVc animated:YES]; [self.navigationController pushViewController:photoPickerVc animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:NO]; [tableView deselectRowAtIndexPath:indexPath animated:NO];
......
...@@ -75,15 +75,17 @@ ...@@ -75,15 +75,17 @@
} }
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == _selectedPhotos.count) { [self pickPhotoButtonClick:nil];} if (indexPath.row == _selectedPhotos.count) {
[self pickPhotoButtonClick:nil];
}
} }
- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath didMoveToIndexPath:(NSIndexPath *)destinationIndexPath { - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)sourceIndexPath didMoveToIndexPath:(NSIndexPath *)destinationIndexPath {
if (sourceIndexPath.item >= _selectedPhotos.count || destinationIndexPath.item >= _selectedPhotos.count) return; if (sourceIndexPath.item >= _selectedPhotos.count || destinationIndexPath.item >= _selectedPhotos.count) return;
UIImage *image = _selectedPhotos[sourceIndexPath.item]; UIImage *image = _selectedPhotos[sourceIndexPath.item];
if (image) { if (image) {
[_selectedPhotos removeObjectAtIndex:sourceIndexPath.item]; [_selectedPhotos exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
[_selectedPhotos insertObject:image atIndex:destinationIndexPath.item]; [_selectedAssets exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
[_collectionView reloadData]; [_collectionView reloadData];
} }
} }
...@@ -149,17 +151,16 @@ ...@@ -149,17 +151,16 @@
/// User finish picking video, /// User finish picking video,
/// 用户选择好了视频 /// 用户选择好了视频
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset { - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingVideo:(UIImage *)coverImage sourceAssets:(id)asset {
[_selectedPhotos addObjectsFromArray:@[coverImage]]; _selectedPhotos = [NSMutableArray arrayWithArray:@[coverImage]];
_selectedAssets = [NSMutableArray arrayWithArray:@[asset]];
_layout.itemCount = _selectedPhotos.count; _layout.itemCount = _selectedPhotos.count;
/*
// open this code to send video / 打开这段代码发送视频 // open this code to send video / 打开这段代码发送视频
[[TZImageManager manager] getVideoOutputPathWithAsset:asset completion:^(NSString *outputPath) { // [[TZImageManager manager] getVideoOutputPathWithAsset:asset completion:^(NSString *outputPath) {
NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath); // NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
// Export completed, send video here, send by outputPath or NSData // Export completed, send video here, send by outputPath or NSData
// 导出完成,在这里写上传代码,通过路径或者通过NSData上传 // 导出完成,在这里写上传代码,通过路径或者通过NSData上传
}]; // }];
*/
[_collectionView reloadData]; [_collectionView reloadData];
_collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH)); _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
} }
......
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