Skip to content

Commit

Permalink
添加资源类型图片
Browse files Browse the repository at this point in the history
  • Loading branch information
hujewelz committed Feb 3, 2018
1 parent ef44c40 commit f69de8e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion HUPhotoPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HUPhotoPicker'
s.version = '1.0.8'
s.version = '1.0.9'
s.summary = '本地图片选择器.'

# This description is used to generate tags and improve search results.
Expand Down
Binary file added HUPhotoPicker/Assets/icon_video@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added HUPhotoPicker/Assets/icon_video@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions HUPhotoPicker/Classes/HUImageGridCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@property (nonatomic, assign) BOOL isDegraded;
@property (nonatomic, copy) NSString *representedAssetIdentifier;

@property (nonatomic, strong) PHAsset *asset;

@property (nonatomic, strong) HUImageSelectModel *model;

@end
40 changes: 36 additions & 4 deletions HUPhotoPicker/Classes/HUImageGridCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#import "HUImageGridCell.h"
#import "Asset.h"
#import "UIView+HUConstraint.h"
//#import "NSBundle+HUPicker.h"
#import <Photos/Photos.h>

@interface HUImageGridCell ()

@property (nonatomic, strong) UIButton *checkButton;
@property (nonatomic, strong) UIImageView *videoIcon;
@property (nonatomic, strong) UIView *disableMask;


@end
Expand Down Expand Up @@ -41,10 +43,16 @@ - (void)setModel:(HUImageSelectModel *)model {
}
}

- (void)setAsset:(PHAsset *)asset {
_asset = asset;
_checkButton.hidden = asset.mediaType != PHAssetMediaTypeImage;
_videoIcon.hidden = asset.mediaType != PHAssetMediaTypeVideo;
_disableMask.hidden = _videoIcon.isHidden;
}

- (void)setIsDegraded:(BOOL)isDegraded {
_isDegraded = isDegraded;
self.degradedButton.hidden = !isDegraded;
// NSLog(@"is degraded: %zd", isDegraded);
}

- (void)setupView {
Expand All @@ -57,10 +65,17 @@ - (void)setupView {
[self.contentView addConstraintsWithVisualFormat:@"H:[v0(==22)]-2-|" views:@[self.checkButton]];
[self.contentView addConstraintsWithVisualFormat:@"V:|-2-[v0(==22)]" views:@[self.checkButton]];


[self.contentView addSubview:self.degradedButton];
[self.contentView addConstraintsWithVisualFormat:@"H:|[v0]|" views:@[self.degradedButton]];
[self.contentView addConstraintsWithVisualFormat:@"V:|[v0]|" views:@[self.degradedButton]];

[self.contentView addSubview:self.disableMask];
[self.contentView addConstraintsWithVisualFormat:@"H:|[v0]|" views:@[self.disableMask]];
[self.contentView addConstraintsWithVisualFormat:@"V:|[v0]|" views:@[self.disableMask]];

[self.contentView addSubview:self.videoIcon];
[self.contentView addConstraintsWithVisualFormat:@"H:[v0]-4-|" views:@[self.videoIcon]];
[self.contentView addConstraintsWithVisualFormat:@"V:|-4-[v0]" views:@[self.videoIcon]];

}

Expand Down Expand Up @@ -88,14 +103,31 @@ - (UIButton *)checkButton {
return _checkButton;
}

- (UIImageView *)videoIcon {
if (_videoIcon == nil) {
_videoIcon = [UIImageView new];
_videoIcon.image = UIImageMake(@"icon_video");
_videoIcon.hidden = YES;
}
return _videoIcon;
}

- (UIButton *)degradedButton {
if (_degradedButton == nil) {
_degradedButton = [UIButton buttonWithType:UIButtonTypeCustom];
_degradedButton.adjustsImageWhenHighlighted = NO;
//_degradedButton.backgroundColor = [UIColor redColor];
_degradedButton.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}
return _degradedButton;
}

- (UIView *)disableMask {
if (_disableMask == nil) {
_disableMask = [UIView new];
_disableMask.backgroundColor = [UIColor colorWithWhite:0 alpha:0.45];
_disableMask.hidden = YES;
}
return _disableMask;
}

@end
2 changes: 1 addition & 1 deletion HUPhotoPicker/Classes/HUImageGridViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

HUImageGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[HUImageGridCell reuseIdentifier] forIndexPath:indexPath];
cell.representedAssetIdentifier = asset.localIdentifier;
cell.asset = asset;
cell.model = self.selectModels[indexPath.item-1];
[_cachingImageManager requestImageForAsset:asset targetSize:_targetSize contentMode:PHImageContentModeDefault options:_options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
BOOL isDegraded = [info[PHImageResultIsDegradedKey] boolValue];

if (result && [cell.representedAssetIdentifier isEqualToString: asset.localIdentifier]) {
cell.thumbnail.image = result;
cell.isDegraded = isDegraded;
Expand Down

0 comments on commit f69de8e

Please sign in to comment.