Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions TZImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@
TargetAttributes = {
900E657B1C2BB8D5003D9A9E = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = 3TA49P2Q58;
DevelopmentTeam = 9YHXDAVF4M;
ProvisioningStyle = Automatic;
};
900E65941C2BB8D5003D9A9E = {
Expand Down Expand Up @@ -854,7 +854,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 3TA49P2Q58;
DEVELOPMENT_TEAM = 9YHXDAVF4M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/TZImagePickerController",
Expand All @@ -879,7 +879,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = LTFQDC2QVX;
DEVELOPMENT_TEAM = 9YHXDAVF4M;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/TZImagePickerController",
Expand Down
2 changes: 2 additions & 0 deletions TZImagePickerController/TZImagePickerController/TZAssetCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ typedef enum : NSUInteger {
@property (nonatomic, copy) void (^didSelectPhotoBlock)(BOOL);
@property (nonatomic, assign) TZAssetCellType type;
@property (nonatomic, assign) BOOL allowPickingGif;
@property (nonatomic, assign) BOOL allowPickingLiveImage;
@property (nonatomic, assign) BOOL allowPickingMultipleVideo;
@property (nonatomic, copy) NSString *representedAssetIdentifier;
@property (nonatomic, assign) int32_t imageRequestID;

@property (nonatomic, strong) UIImage *photoSelImage;
@property (nonatomic, strong) UIImage *photoDefImage;
@property (nonatomic, strong) UIImageView *toggleLiveImageView;

@property (nonatomic, assign) BOOL showSelectBtn;
@property (assign, nonatomic) BOOL allowPreview;
Expand Down
22 changes: 20 additions & 2 deletions TZImagePickerController/TZImagePickerController/TZAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ - (void)setType:(TZAssetCellType)type {
_selectPhotoButton.hidden = YES;
}

_toggleLiveImageView.hidden = YES;

if (type == TZAssetCellTypeVideo) {
self.bottomView.hidden = NO;
self.timeLength.text = _model.timeLength;
Expand All @@ -121,6 +123,8 @@ - (void)setType:(TZAssetCellType)type {
self.videoImgView.hidden = YES;
_timeLength.tz_left = 5;
_timeLength.textAlignment = NSTextAlignmentLeft;
}else if (type == TZAssetCellTypeLivePhoto && self.allowPickingLiveImage) {
self.toggleLiveImageView.hidden = NO;
}
}

Expand Down Expand Up @@ -338,7 +342,18 @@ - (UILabel *)indexLabel {
}
return _indexLabel;
}

- (UIImageView *)toggleLiveImageView{
if (!_toggleLiveImageView) {
UIImage *image = [UIImage tz_imageNamedFromMyBundle:@"photo_livephoto"];
if (@available(iOS 13.0, *)) {
image = [[UIImage systemImageNamed:@"livephoto"] imageWithTintColor:UIColor.whiteColor renderingMode:UIImageRenderingModeAlwaysOriginal];
}
_toggleLiveImageView = [[UIImageView alloc]initWithImage:image];
_toggleLiveImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:_toggleLiveImageView];
}
return _toggleLiveImageView;
}
- (TZProgressView *)progressView {
if (_progressView == nil) {
_progressView = [[TZProgressView alloc] init];
Expand All @@ -365,6 +380,8 @@ - (void)layoutSubviews {
_indexLabel.frame = _selectImageView.frame;
_imageView.frame = self.bounds;

self.toggleLiveImageView.frame = CGRectMake(3, 3, 18, 18);

static CGFloat progressWH = 20;
CGFloat progressXY = (self.tz_width - progressWH) / 2;
_progressView.frame = CGRectMake(progressXY, progressXY, progressWH, progressWH);
Expand All @@ -381,7 +398,8 @@ - (void)layoutSubviews {
[self.contentView bringSubviewToFront:_selectPhotoButton];
[self.contentView bringSubviewToFront:_selectImageView];
[self.contentView bringSubviewToFront:_indexLabel];

[self.contentView bringSubviewToFront:_toggleLiveImageView];

if (self.assetCellDidLayoutSubviewsBlock) {
self.assetCellDidLayoutSubviewsBlock(self, _imageView, _selectImageView, _indexLabel, _bottomView, _timeLength, _videoImgView);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) TZAssetModelMediaType type;
@property (nonatomic, copy) NSString *timeLength;
@property (nonatomic, assign) BOOL iCloudFailed;
/// 是否使用 Live Photo 模式,默认 YES
@property (nonatomic, assign) BOOL useLivePhoto;

/// Init a photo dataModel With a PHAsset
/// 用一个PHAsset实例,初始化一个照片模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ + (instancetype)modelWithAsset:(PHAsset *)asset type:(TZAssetModelMediaType)type
model.asset = asset;
model.isSelected = NO;
model.type = type;
model.useLivePhoto = (model.type == TZAssetModelMediaTypeLivePhoto ? YES:NO);
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
// 该方法中,completion只会走一次
- (PHImageRequestID)getOriginalPhotoDataWithAsset:(PHAsset *)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
- (PHImageRequestID)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
/// Get livePhoto 获得实况图照片
- (PHImageRequestID)getLivePhotoWithAsset:(PHAsset *)asset completion:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler;


/// Get Image For VideoURL
- (UIImage *)getImageWithVideoURL:(NSURL *)videoURL;
Expand Down
43 changes: 41 additions & 2 deletions TZImagePickerController/TZImagePickerController/TZImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ @interface TZImageManager ()
@end

@implementation TZImageManager
{
PHCachingImageManager *_phCachingImageManager;
}

CGSize AssetGridThumbnailSize;
CGFloat TZScreenWidth;
Expand Down Expand Up @@ -257,7 +260,8 @@ - (TZAssetModel *)assetModelWithAsset:(PHAsset *)asset allowPickingVideo:(BOOL)a
if (!allowPickingVideo && type == TZAssetModelMediaTypeVideo) return nil;
if (!allowPickingImage && type == TZAssetModelMediaTypePhoto) return nil;
if (!allowPickingImage && type == TZAssetModelMediaTypePhotoGif) return nil;

if (!allowPickingImage && type == TZAssetModelMediaTypeLivePhoto) return nil;

PHAsset *phAsset = (PHAsset *)asset;
if (self.hideWhenCanNotSelect) {
// 过滤掉尺寸不满足要求的图片
Expand All @@ -278,7 +282,10 @@ - (TZAssetModelMediaType)getAssetType:(PHAsset *)asset {
else if (phAsset.mediaType == PHAssetMediaTypeAudio) type = TZAssetModelMediaTypeAudio;
else if (phAsset.mediaType == PHAssetMediaTypeImage) {
if (@available(iOS 9.1, *)) {
// if (asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) type = TZAssetModelMediaTypeLivePhoto;
// PHAssetMediaSubtype 是一个 位掩码(bitmask)类型,多个值可以 按位“或”组合在一起,判断一个类型是否包含某一项(比如是否包含 Live)时,不能用 ==
// asset.mediaSubtypes & PHAssetMediaSubtypePhotoLive 等价于:
// 判断 asset.mediaSubtypes 的二进制值中,是否包含 Live Photo(1 << 2,对应二进制位是00000100)
if (asset.mediaSubtypes & PHAssetMediaSubtypePhotoLive) type = TZAssetModelMediaTypeLivePhoto;
}
// Gif
if ([[phAsset valueForKey:@"filename"] hasSuffix:@"GIF"]) {
Expand Down Expand Up @@ -504,6 +511,31 @@ - (PHImageRequestID)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandl
}];
}

- (PHImageRequestID)getLivePhotoWithAsset:(PHAsset *)asset completion:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler{
if (!asset) {
if (completion) completion(nil, nil);
return -1;
}
if ([[PHCachingImageManager class] instancesRespondToSelector:@selector(requestLivePhotoForAsset:targetSize:contentMode:options:resultHandler:)]) {
PHLivePhotoRequestOptions *livePhotoRequestOptions = [[PHLivePhotoRequestOptions alloc] init];
livePhotoRequestOptions.networkAccessAllowed = YES; // 允许访问网络
livePhotoRequestOptions.progressHandler = phProgressHandler;
int32_t imageRequestID = [[[TZImageManager manager] phCachingImageManager] requestLivePhotoForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeAspectFit
options:livePhotoRequestOptions
resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) {
if (completion) {
completion(livePhoto, info);
}
}];
return imageRequestID;
}else {
if (completion) completion(nil, nil);
return -1;
}
}

- (UIImage *)getImageWithVideoURL:(NSURL *)videoURL {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
if (!asset) {
Expand Down Expand Up @@ -1063,6 +1095,13 @@ - (UIImage *)fixOrientation:(UIImage *)aImage {
return img;
}

- (PHCachingImageManager *)phCachingImageManager {
if (!_phCachingImageManager) {
_phCachingImageManager = [[PHCachingImageManager alloc] init];
}
return _phCachingImageManager;
}

#pragma clang diagnostic pop

@end
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
/// 默认为YES,如果设置为NO,用户将不能选择发送图片
@property (nonatomic, assign) BOOL allowPickingImage;

/// Default is NO, if set YES, user can picking liveImage.
/// 默认为NO,如果设置为YES,用户将能选择发送实况图片
@property (nonatomic, assign) BOOL allowPickingLiveImage;


/// Default is YES, if set NO, user can't take picture.
/// 默认为YES,如果设置为NO, 用户将不能拍摄照片
@property (nonatomic, assign) BOOL allowTakePicture;
Expand Down Expand Up @@ -383,6 +388,7 @@
+ (instancetype)sharedInstance;
@property (copy, nonatomic) NSString *preferredLanguage;
@property(nonatomic, assign) BOOL allowPickingImage;
@property (nonatomic, assign) BOOL allowPickingLiveImage;
@property (nonatomic, assign) BOOL allowPickingVideo;
@property (strong, nonatomic) NSBundle *languageBundle;
@property (assign, nonatomic) BOOL showSelectedIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ - (instancetype)initWithMaxImagesCount:(NSInteger)maxImagesCount columnNumber:(N
self.allowPickingOriginalPhoto = YES;
self.allowPickingVideo = YES;
self.allowPickingImage = YES;
self.allowPickingLiveImage = YES;
self.allowTakePicture = YES;
self.allowTakeVideo = YES;
self.videoMaximumDuration = 10 * 60;
Expand Down Expand Up @@ -521,6 +522,7 @@ - (void)setAllowCrop:(BOOL)allowCrop {
if (allowCrop) { // 允许裁剪的时候,不能选原图和GIF
self.allowPickingOriginalPhoto = NO;
self.allowPickingGif = NO;
self.allowPickingLiveImage = NO;
self.photoWidth = 1200;
self.photoPreviewMaxWidth = 1200;
}
Expand Down Expand Up @@ -632,6 +634,14 @@ - (void)setAllowPickingImage:(BOOL)allowPickingImage {
}
}

- (void)setAllowPickingLiveImage:(BOOL)allowPickingLiveImage{
_allowPickingLiveImage = allowPickingLiveImage;
[TZImagePickerConfig sharedInstance].allowPickingLiveImage = allowPickingLiveImage;
if (!allowPickingLiveImage) {
_allowPickingLiveImage = NO;
}
}

- (void)setAllowPickingVideo:(BOOL)allowPickingVideo {
_allowPickingVideo = allowPickingVideo;
[TZImagePickerConfig sharedInstance].allowPickingVideo = allowPickingVideo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,13 @@ - (void)doneButtonClick {
}
[photos replaceObjectAtIndex:i withObject:photo];
}
if (info) [infoArr replaceObjectAtIndex:i withObject:info];
NSMutableDictionary *infoDict = [NSMutableDictionary dictionary];
if (info) {
infoDict = [NSMutableDictionary dictionaryWithDictionary:info];
}
if (model.type == TZAssetModelMediaTypeLivePhoto && model.useLivePhoto) {
[infoDict setObject:@"1" forKey:@"TZ_LIVEPHOTO_USELIVE"];
}
[assets replaceObjectAtIndex:i withObject:model.asset];

for (id item in photos) { if ([item isKindOfClass:[NSNumber class]]) return; }
Expand Down Expand Up @@ -636,6 +642,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
model = _models[indexPath.item - diff];;
}
cell.allowPickingGif = tzImagePickerVc.allowPickingGif;
cell.allowPickingLiveImage = tzImagePickerVc.allowPickingLiveImage;
cell.model = model;
if (model.isSelected && tzImagePickerVc.showSelectedIndex) {
cell.index = [tzImagePickerVc.selectedAssetIds indexOfObject:model.asset.localIdentifier] + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import <PhotosUI/PhotosUI.h>

@class TZAssetModel;
@interface TZAssetPreviewCell : UICollectionViewCell
Expand Down Expand Up @@ -74,3 +75,33 @@
@interface TZGifPreviewCell : TZAssetPreviewCell
@property (strong, nonatomic) TZPhotoPreviewView *previewView;
@end


@interface TZLivePhotoPreviewCell : TZAssetPreviewCell

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *imageContainerView;
@property (nonatomic, strong) TZProgressView *progressView;
@property (nonatomic, strong) UIImageView *iCloudErrorIcon;
@property (nonatomic, strong) UILabel *iCloudErrorLabel;
@property (nonatomic, strong) UIButton *useLivePhotoButton;
@property (nonatomic, strong) PHLivePhotoView *livePhotoView;

@property (nonatomic, copy) void (^iCloudSyncFailedHandle)(id asset, BOOL isSyncFailed);

@property (nonatomic, strong) id asset;
@property (nonatomic, strong) PHLivePhoto *livePhoto;
@property (nonatomic, copy) void (^imageProgressUpdateBlock)(double progress);

@property (nonatomic, assign) int32_t imageRequestID;

@property (nonatomic, assign) BOOL canPlayLivePhoto;

- (void)recoverSubviews;

- (void)prepareForDisplay;

- (void)prepareForHide;

@end
Loading