Skip to content

Commit

Permalink
add SDWebImage & add isShowSelectedState
Browse files Browse the repository at this point in the history
  • Loading branch information
dong committed Apr 24, 2019
1 parent 6844d0e commit 8c39496
Show file tree
Hide file tree
Showing 62 changed files with 221 additions and 2,273 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ xcuserdata/
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/

# Carthage
#
Expand Down
3 changes: 2 additions & 1 deletion JPTagView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pod::Spec.new do |s|

s.name = "JPTagView"
s.version = "1.5.0"
s.version = "1.5.1"
s.summary = "Customized tag pages."
s.homepage = "https://github.com/baiyidjp/JPTagViewDemo"
s.license = "MIT"
Expand All @@ -12,6 +12,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/baiyidjp/JPTagViewDemo.git", :tag => "#{s.version}" }
s.source_files = "JPTagView/*.{h,m}"
s.requires_arc = true
s.dependency "SDWebImage"
# pod trunk push --allow-warnings
# 将修改文件copy到JPTagView
end
4 changes: 2 additions & 2 deletions JPTagView/JPTagCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (void)setTagModel:(JPTagModel *)tagModel {

if (tagModel.tagBackSelectedImageUrl && tagModel.tagBackSelectedImageUrl.length) {
//下载网络图片
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagModel.tagBackSelectedImageUrl] completed:^(UIImage * _Nullable image, NSURL * _Nullable imageURL) {
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagModel.tagBackSelectedImageUrl] completed:^(UIImage * image) {

[self p_HandleTagBackImage:image tagModel:tagModel];
}];
Expand All @@ -97,7 +97,7 @@ - (void)setTagModel:(JPTagModel *)tagModel {

if (tagModel.tagBackNormalImageUrl && tagModel.tagBackNormalImageUrl.length) {
//下载网络图片
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagModel.tagBackNormalImageUrl] completed:^(UIImage * _Nullable image, NSURL * _Nullable imageURL) {
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagModel.tagBackNormalImageUrl] completed:^(UIImage * image) {

[self p_HandleTagBackImage:image tagModel:tagModel];
}];
Expand Down
3 changes: 2 additions & 1 deletion JPTagView/JPTagModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ typedef NS_OPTIONS(NSUInteger, TagDeleteCorner) {
@property(nonatomic,assign) BOOL isShowShakeAnimation;
/** isCanSelectedTag default YES */
@property(nonatomic,assign) BOOL isCanSelectedTag;

/** isShowSelectedState default YES */
@property(nonatomic,assign) BOOL isShowSelectedState;

/** tag section height default 50 */
@property(nonatomic,assign) CGFloat tagSectionHeight;
Expand Down
61 changes: 0 additions & 61 deletions JPTagView/JPTagView.bundle/Root.plist

This file was deleted.

Binary file removed JPTagView/JPTagView.bundle/en.lproj/Root.strings
Binary file not shown.
5 changes: 4 additions & 1 deletion JPTagView/JPTagView.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ NS_ASSUME_NONNULL_BEGIN

//删除相关

/** tagDeleteImage */
/** tagDeleteImage default [UIImage imageNamed:@""] */
@property(nonatomic,strong) UIImage *tagDeleteImage;

/** isShowDelete default NO 展示delete 设置 tagBackContentInset 至少为 4.4.4.4 */
Expand All @@ -181,6 +181,9 @@ NS_ASSUME_NONNULL_BEGIN
/** isCanSelectedTag default YES */
@property(nonatomic,assign) BOOL isCanSelectedTag;

/** isShowSelectedState default YES */
@property(nonatomic,assign) BOOL isShowSelectedState;

/** isTagCanClickWhenSelected 是否可以点击已选中的tag default YES */
@property(nonatomic,assign) BOOL isTagCanClickWhenSelected;

Expand Down
15 changes: 12 additions & 3 deletions JPTagView/JPTagView.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ - (void)p_ConfigDefaultData {
self.tagMinHeight = 30;
self.tagNameContentInset = UIEdgeInsetsMake(6, 14, 6, 14);

NSBundle *tagViewBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"JPTagView" ofType:@"bundle"]];
self.tagDeleteImage = [UIImage imageWithContentsOfFile:[tagViewBundle pathForResource:@"icon_delete@2x" ofType:@"png"]];
self.tagDeleteImage = [UIImage imageNamed:@""];
self.isShowDelete = NO;
self.isShowSelectedState = YES;
self.isTagCanClickWhenSelected = YES;
self.isCanLongPressShowDelete = NO;
self.isShakeWhenShowDelete = NO;
Expand Down Expand Up @@ -229,6 +229,14 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
return;
}

if (!tagModel.isShowSelectedState) {

if (self.delegate && [self.delegate respondsToSelector:@selector(tagView:didSelectedItem:)]) {
[self.delegate tagView:self didSelectedItem:indexPath];
}
return;
}

if (tagModel.isSelected && !tagModel.isTagCanClickWhenSelected) {

if (self.delegate && [self.delegate respondsToSelector:@selector(tagView:didSelectedItem:)]) {
Expand Down Expand Up @@ -412,6 +420,7 @@ - (void)setTagViewDataWith:(NSArray<JPTagModel *> *)dataArray {
tagModel.isTagCanClickWhenSelected = self.isTagCanClickWhenSelected;
tagModel.isShakeWhenShowDelete = self.isShakeWhenShowDelete;
tagModel.isCanSelectedTag = self.isCanSelectedTag;
tagModel.isShowSelectedState = self.isShowSelectedState;

tagModel.tagNameNormalFont = self.tagNameNormalFont;
tagModel.tagNameSelectedFont = self.tagNameSelectedFont;
Expand Down Expand Up @@ -624,7 +633,7 @@ - (void)setTagViewBackImageUrl:(NSString *)tagViewBackImageUrl {

self.tagViewBackImageView.hidden = NO;
//下载网络图片
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagViewBackImageUrl] completed:^(UIImage * _Nullable image, NSURL * _Nullable imageURL) {
[UIImageView jp_downloadImageWithURL:[NSURL URLWithString:tagViewBackImageUrl] completed:^(UIImage * image) {

self.tagViewBackImageView.image = image;
}];
Expand Down
9 changes: 1 addition & 8 deletions JPTagView/UIImageView+JPCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@

NS_ASSUME_NONNULL_BEGIN

typedef void(^JPExternalCompletionBlock)(UIImage * _Nullable image, NSURL * _Nullable imageURL);
typedef void(^JPExternalCompletionBlock)(UIImage * image);

@interface UIImageView (JPCategory)

/**
设置图片
@param url NSURL图片地址
*/
- (void)jp_setImageWithURL:(NSURL *)url completed:(JPExternalCompletionBlock)completedBlock;

/**
下载图片
Expand Down
103 changes: 10 additions & 93 deletions JPTagView/UIImageView+JPCategory.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,111 +7,28 @@
//

#import "UIImageView+JPCategory.h"
#import "SDWebImageDownloader.h"

@implementation UIImageView (JPCategory)

- (void)jp_setImageWithURL:(NSURL *)url completed:(nonnull JPExternalCompletionBlock)completedBlock {
+ (void)jp_downloadImageWithURL:(NSURL *)url completed:(nonnull JPExternalCompletionBlock)completedBlock {

if (!url){
if (!url || ![url absoluteString].length ){
return;
}
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"JPDownloadImageCache"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDirExist = [fileManager fileExistsAtPath:path];
if(!isDirExist){

BOOL bCreateDir = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
if (!bCreateDir) {
NSLog(@"创建文件出错");
return;
}
}
NSString *urlString = [url absoluteString];
NSString *imageName = [[urlString componentsSeparatedByString:@"/"] lastObject];
NSString *pathString = [[path stringByAppendingString:@"/"] stringByAppendingString:imageName];
NSData *saveData = [NSData dataWithContentsOfFile:pathString];
//本地缓存
if (saveData) {
UIImage *saveImage = [UIImage imageWithData:saveData];
self.image = saveImage;
if (completedBlock) {
completedBlock(saveImage,url);
}
return;
}
//创建会话对象
NSURLSession *session = [NSURLSession sharedSession];
//创建会话请求
NSURLSessionDownloadTask *downTask = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {

[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:url options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {

dispatch_async(dispatch_get_main_queue(), ^{
if (location && location.absoluteString.length) {

[fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:pathString] error:nil];
NSData *saveData = [NSData dataWithContentsOfFile:pathString];
if (saveData) {
UIImage *saveImage = [UIImage imageWithData:saveData];
self.image = saveImage;
if (completedBlock) {
completedBlock(saveImage,url);
}
if (finished) {

if (error == nil && image) {
if (completedBlock) {
completedBlock(image);
}
}
});
}];
//发送请求
[downTask resume];
}

+ (void)jp_downloadImageWithURL:(NSURL *)url completed:(JPExternalCompletionBlock)completedBlock {

if (!url){
return;
}
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"JPDownloadImageCache"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDirExist = [fileManager fileExistsAtPath:path];
if(!isDirExist){

BOOL bCreateDir = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
if (!bCreateDir) {
NSLog(@"创建文件出错");
return;
}
}
NSString *urlString = [url absoluteString];
NSString *imageName = [[urlString componentsSeparatedByString:@"/"] lastObject];
NSString *pathString = [[path stringByAppendingString:@"/"] stringByAppendingString:imageName];
NSData *cacheData = [NSData dataWithContentsOfFile:pathString];
//本地缓存
if (cacheData) {
UIImage *cacheImage = [UIImage imageWithData:cacheData];
if (completedBlock) {
completedBlock(cacheImage,url);
}
return;
}
//创建会话对象
NSURLSession *session = [NSURLSession sharedSession];
//创建会话请求
NSURLSessionDownloadTask *downTask = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {

dispatch_async(dispatch_get_main_queue(), ^{
if (location && location.absoluteString.length) {

[fileManager moveItemAtURL:location toURL:[NSURL fileURLWithPath:pathString] error:nil];
NSData *saveData = [NSData dataWithContentsOfFile:pathString];
if (saveData) {
UIImage *saveImage = [UIImage imageWithData:saveData];
if (completedBlock) {
completedBlock(saveImage,url);
}
}
}
});
}];
//发送请求
[downTask resume];
}

@end
Loading

0 comments on commit 8c39496

Please sign in to comment.