Skip to content

Commit

Permalink
1.7.3版本 主要优化了iCloud图片的显示与选择
Browse files Browse the repository at this point in the history
  • Loading branch information
banchichen committed Dec 6, 2016
1 parent 55f0f42 commit d7bf525
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 381 deletions.
4 changes: 2 additions & 2 deletions TZImagePickerController.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "TZImagePickerController"
s.version = "1.7.2"
s.version = "1.7.3"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT"
s.author = { "banchichen" => "tanzhenios@foxmail.com" }
s.platform = :ios
s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.2" }
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.3" }
s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
Expand Down
6 changes: 6 additions & 0 deletions TZImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
6D5358CD1D64600F00928CC6 /* NSBundle+TZImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D5358CC1D64600F00928CC6 /* NSBundle+TZImagePicker.m */; };
6DC358661CC8BAFD00898D29 /* TZImagePickerController.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */; };
6DC84D0A1DF5358500A107A9 /* TZImageCropManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DC84D091DF5358500A107A9 /* TZImageCropManager.m */; };
6DD0502B1DF659ED0057C78D /* TZProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DD0502A1DF659ED0057C78D /* TZProgressView.m */; };
900E65811C2BB8D5003D9A9E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65801C2BB8D5003D9A9E /* main.m */; };
900E65841C2BB8D5003D9A9E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65831C2BB8D5003D9A9E /* AppDelegate.m */; };
900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 900E65861C2BB8D5003D9A9E /* ViewController.m */; };
Expand Down Expand Up @@ -58,6 +59,8 @@
6DC358651CC8BAFD00898D29 /* TZImagePickerController.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TZImagePickerController.bundle; sourceTree = "<group>"; };
6DC84D081DF5358500A107A9 /* TZImageCropManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZImageCropManager.h; sourceTree = "<group>"; };
6DC84D091DF5358500A107A9 /* TZImageCropManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZImageCropManager.m; sourceTree = "<group>"; };
6DD050291DF659ED0057C78D /* TZProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZProgressView.h; sourceTree = "<group>"; };
6DD0502A1DF659ED0057C78D /* TZProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZProgressView.m; sourceTree = "<group>"; };
900E657C1C2BB8D5003D9A9E /* TZImagePickerController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TZImagePickerController.app; sourceTree = BUILT_PRODUCTS_DIR; };
900E65801C2BB8D5003D9A9E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
900E65821C2BB8D5003D9A9E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -213,6 +216,8 @@
900EF0141C2C134900EA709B /* TZPhotoPreviewCell.m */,
90CE84B51C3BABB6003D0779 /* TZVideoPlayerController.h */,
90CE84B61C3BABB6003D0779 /* TZVideoPlayerController.m */,
6DD050291DF659ED0057C78D /* TZProgressView.h */,
6DD0502A1DF659ED0057C78D /* TZProgressView.m */,
90CE84AC1C3A89EF003D0779 /* TZImageManager.h */,
90CE84AD1C3A89EF003D0779 /* TZImageManager.m */,
6DC84D081DF5358500A107A9 /* TZImageCropManager.h */,
Expand Down Expand Up @@ -364,6 +369,7 @@
90EBF5D61C2E298000CB9BCC /* UIView+Layout.m in Sources */,
90CE84B71C3BABB6003D0779 /* TZVideoPlayerController.m in Sources */,
900EF0021C2BD7E400EA709B /* TZAssetCell.m in Sources */,
6DD0502B1DF659ED0057C78D /* TZProgressView.m in Sources */,
6D32B9BD1CD83640005CE1E0 /* LxGridViewFlowLayout.m in Sources */,
900EF0161C2C134900EA709B /* TZPhotoPreviewCell.m in Sources */,
900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion TZImagePickerController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.7.2</string>
<string>1.7.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand All @@ -39,6 +39,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Expand Down
73 changes: 55 additions & 18 deletions TZImagePickerController/TZImagePickerController/TZAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "UIView+Layout.h"
#import "TZImageManager.h"
#import "TZImagePickerController.h"
#import "TZProgressView.h"

@interface TZAssetCell ()
@property (weak, nonatomic) UIImageView *imageView; // The photo / 照片
Expand All @@ -19,26 +20,22 @@ @interface TZAssetCell ()
@property (weak, nonatomic) UILabel *timeLength;

@property (nonatomic, weak) UIImageView *viewImgView;

@property (nonatomic, strong) TZProgressView *progressView;
@property (nonatomic, assign) PHImageRequestID bigImageRequestID;
@end

@implementation TZAssetCell

// Now we use code to create subViews for improve performance
// 现在我们用代码来创建TZAssetCell和TZAlbumCell的子控件,以提高性能

/*
- (void)awakeFromNib {
self.timeLength.font = [UIFont boldSystemFontOfSize:11];
}
*/

- (void)setModel:(TZAssetModel *)model {
_model = model;
if (iOS8Later) {
self.representedAssetIdentifier = [[TZImageManager manager] getAssetIdentifier:model.asset];
}
PHImageRequestID imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.tz_width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (_progressView) {
self.progressView.hidden = YES;
self.imageView.alpha = 1.0;
}
// Set the cell's thumbnail image if it's still showing the same asset.
if (!iOS8Later) {
self.imageView.image = photo; return;
Expand All @@ -52,7 +49,7 @@ - (void)setModel:(TZAssetModel *)model {
if (!isDegraded) {
self.imageRequestID = 0;
}
}];
} progressHandler:nil networkAccessAllowed:NO];
if (imageRequestID && self.imageRequestID && imageRequestID != self.imageRequestID) {
[[PHImageManager defaultManager] cancelImageRequest:self.imageRequestID];
// NSLog(@"cancelImageRequest %d",self.imageRequestID);
Expand All @@ -75,6 +72,10 @@ - (void)setModel:(TZAssetModel *)model {
_selectImageView.hidden = YES;
}
}
// 如果用户选中了该图片,提前获取一下大图
if (model.isSelected) {
[self fetchBigImage];
}
}

- (void)setShowSelectBtn:(BOOL)showSelectBtn {
Expand Down Expand Up @@ -107,10 +108,40 @@ - (void)selectPhotoButtonClick:(UIButton *)sender {
self.selectImageView.image = sender.isSelected ? [UIImage imageNamedFromMyBundle:self.photoSelImageName] : [UIImage imageNamedFromMyBundle:self.photoDefImageName];
if (sender.isSelected) {
[UIView showOscillatoryAnimationWithLayer:_selectImageView.layer type:TZOscillatoryAnimationToBigger];
// 用户选中了该图片,提前获取一下大图
[self fetchBigImage];
} else { // 取消选中,取消大图的获取
if (_bigImageRequestID && _progressView) {
[[PHImageManager defaultManager] cancelImageRequest:_bigImageRequestID];
[self hideProgressView];
}
}
}

#pragma mark - Lazy load
- (void)hideProgressView {
self.progressView.hidden = YES;
self.imageView.alpha = 1.0;
}

- (void)fetchBigImage {
_bigImageRequestID = [[TZImageManager manager] getPhotoWithAsset:_model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
if (_progressView) {
[self hideProgressView];
}
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
if (_model.isSelected) {
progress = progress > 0.02 ? progress : 0.02;;
self.progressView.progress = progress;
self.progressView.hidden = NO;
self.imageView.alpha = 0.4;
} else {
*stop = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
} networkAccessAllowed:YES];
}

#pragma mark - Lazy load

- (UIButton *)selectPhotoButton {
if (_selectImageView == nil) {
Expand Down Expand Up @@ -184,6 +215,18 @@ - (UILabel *)timeLength {
return _timeLength;
}

- (TZProgressView *)progressView {
if (_progressView == nil) {
_progressView = [[TZProgressView alloc] init];
static CGFloat progressWH = 20;
CGFloat progressXY = (self.tz_width - progressWH) / 2;
_progressView.hidden = YES;
_progressView.frame = CGRectMake(progressXY, progressXY, progressWH, progressWH);
[self addSubview:_progressView];
}
return _progressView;
}

@end

@interface TZAlbumCell ()
Expand All @@ -194,12 +237,6 @@ @interface TZAlbumCell ()

@implementation TZAlbumCell

/*
- (void)awakeFromNib {
self.posterImageView.clipsToBounds = YES;
}
*/

- (void)setModel:(TZAlbumModel *)model {
_model = model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) NSArray *models;
@property (nonatomic, strong) NSArray *selectedModels;
@property (nonatomic, assign) NSUInteger selectedCount;
@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@

/// Get photo 获得照片
- (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion;

- (PHImageRequestID)getPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (PHImageRequestID)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
- (PHImageRequestID)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;
- (PHImageRequestID)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;

- (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
- (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info))completion;

Expand Down

0 comments on commit d7bf525

Please sign in to comment.