diff --git a/Podfile b/Podfile index b1b5b81f..b4d7b05f 100644 --- a/Podfile +++ b/Podfile @@ -15,6 +15,8 @@ target 'xplan-ios' do pod 'NTESQuickPass', '~> 2.1.6' #模型转化 pod 'MJExtension' + #图片加载 + pod 'SDWebImage' #登录的 pod 'mob_sharesdk' pod 'mob_sharesdk/ShareSDKPlatforms/QQ' diff --git a/Podfile.lock b/Podfile.lock index 4e553d01..cbc9f6a3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -34,6 +34,9 @@ PODS: - MOBFoundation (3.2.27) - NTESQuickPass (2.1.9) - ReactiveObjC (3.1.1) + - SDWebImage (5.11.1): + - SDWebImage/Core (= 5.11.1) + - SDWebImage/Core (5.11.1) - YYText (1.0.7) DEPENDENCIES: @@ -47,6 +50,7 @@ DEPENDENCIES: - mob_sharesdk/ShareSDKPlatforms/WeChat - NTESQuickPass (~> 2.1.6) - ReactiveObjC + - SDWebImage - YYText SPEC REPOS: @@ -59,6 +63,7 @@ SPEC REPOS: - MOBFoundation - NTESQuickPass - ReactiveObjC + - SDWebImage - YYText SPEC CHECKSUMS: @@ -70,8 +75,9 @@ SPEC CHECKSUMS: MOBFoundation: efdc3ce6b843fbc10ae8c1c6122a02b0d845b39b NTESQuickPass: 8431dc52737c95883cd382c2ee75664d58f39377 ReactiveObjC: 011caa393aa0383245f2dcf9bf02e86b80b36040 + SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d YYText: 5c461d709e24d55a182d1441c41dc639a18a4849 -PODFILE CHECKSUM: 82677bb54bd8940f2a6cc6f00b6eaefb58c721b7 +PODFILE CHECKSUM: 687d511184d9d6e28c8efe12fb40a25936953ff4 COCOAPODS: 1.10.1 diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index 28456c33..55949d20 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -85,6 +85,8 @@ E872308926E89BE000B90D4F /* LoginPhoneViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308826E89BE000B90D4F /* LoginPhoneViewController.m */; }; E872308D26E89DAA00B90D4F /* LoginInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872308C26E89DAA00B90D4F /* LoginInputView.m */; }; E872309326E8D31500B90D4F /* LoginVerifCodeView.m in Sources */ = {isa = PBXBuildFile; fileRef = E872309226E8D31500B90D4F /* LoginVerifCodeView.m */; }; + E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */; }; + E8AC721026F43955007D6E91 /* UIImageViewConstant.m in Sources */ = {isa = PBXBuildFile; fileRef = E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */; }; E8B825B726E9A7D8009E8E9F /* BaseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825B626E9A7D8009E8E9F /* BaseObject.m */; }; E8B825BF26E9E57D009E8E9F /* LoginTicketInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825BE26E9E57D009E8E9F /* LoginTicketInfo.m */; }; E8B825C226EA00DF009E8E9F /* LoginVerifCodePresent.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825C126EA00DF009E8E9F /* LoginVerifCodePresent.m */; }; @@ -259,6 +261,10 @@ E872308C26E89DAA00B90D4F /* LoginInputView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginInputView.m; sourceTree = ""; }; E872309126E8D31500B90D4F /* LoginVerifCodeView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginVerifCodeView.h; sourceTree = ""; }; E872309226E8D31500B90D4F /* LoginVerifCodeView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginVerifCodeView.m; sourceTree = ""; }; + E8AC720B26F435F5007D6E91 /* UIImageView+LoadImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImageView+LoadImage.h"; sourceTree = ""; }; + E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+LoadImage.m"; sourceTree = ""; }; + E8AC720E26F43955007D6E91 /* UIImageViewConstant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIImageViewConstant.h; sourceTree = ""; }; + E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIImageViewConstant.m; sourceTree = ""; }; E8B825B526E9A7D8009E8E9F /* BaseObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseObject.h; sourceTree = ""; }; E8B825B626E9A7D8009E8E9F /* BaseObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseObject.m; sourceTree = ""; }; E8B825BD26E9E57D009E8E9F /* LoginTicketInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginTicketInfo.h; sourceTree = ""; }; @@ -464,6 +470,7 @@ 189DD56C26DF5B5400AB55B1 /* UI */ = { isa = PBXGroup; children = ( + E8AC720A26F435AF007D6E91 /* UIImageView */, E81366F926F0D27A0076364C /* UIButton */, 189DD54926DE338800AB55B1 /* BaseViewController.h */, 189DD54A26DE338800AB55B1 /* BaseViewController.m */, @@ -752,6 +759,17 @@ path = CustomView; sourceTree = ""; }; + E8AC720A26F435AF007D6E91 /* UIImageView */ = { + isa = PBXGroup; + children = ( + E8AC720B26F435F5007D6E91 /* UIImageView+LoadImage.h */, + E8AC720C26F435F5007D6E91 /* UIImageView+LoadImage.m */, + E8AC720E26F43955007D6E91 /* UIImageViewConstant.h */, + E8AC720F26F43955007D6E91 /* UIImageViewConstant.m */, + ); + path = UIImageView; + sourceTree = ""; + }; E8B825BC26E9E520009E8E9F /* Model */ = { isa = PBXGroup; children = ( @@ -1009,6 +1027,7 @@ 189DD54B26DE338800AB55B1 /* BaseViewController.m in Sources */, E8E70D8626F2F55C00F03460 /* XPMineAccountView.m in Sources */, E81C279026EB314D0031E639 /* LoginForgetEditView.m in Sources */, + E8AC721026F43955007D6E91 /* UIImageViewConstant.m in Sources */, E81C27A026EEF83D0031E639 /* XPHtmlUrl.m in Sources */, 18E7B1B726E8B2D10064BC9B /* Api+Main.m in Sources */, E8B825C226EA00DF009E8E9F /* LoginVerifCodePresent.m in Sources */, @@ -1018,6 +1037,7 @@ 18E7B31E26F0984C0064BC9B /* UserLevelVo.m in Sources */, 18E7B31B26F0982E0064BC9B /* UserExpand.m in Sources */, E8B825CD26EA18C8009E8E9F /* ThemeColor.m in Sources */, + E8AC720D26F435F5007D6E91 /* UIImageView+LoadImage.m in Sources */, E8CEA03D26EA3DE500644B44 /* LoginPasswordPresent.m in Sources */, E8E70D7726F2F15100F03460 /* XPMineViewController.m in Sources */, 189DD52E26DE255300AB55B1 /* AppDelegate.m in Sources */, diff --git a/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.h b/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.h new file mode 100644 index 00000000..692cfe2b --- /dev/null +++ b/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.h @@ -0,0 +1,53 @@ +// +// UIImageView+LoadImage.h +// xplan-ios +// +// Created by 冯硕 on 2021/9/17. +// 加载图片的类 + +#import +#import "UIImageViewConstant.h" +NS_ASSUME_NONNULL_BEGIN + +@interface UIImageView (LoadImage) +/// 加载图片 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +/// @param cornerRadious 弧度 +/// @param success 成功的回调 +- (void)load_setImageImageWithUrl:(NSString *)url + placeholderImage:(NSString *)placeholderImage + type:(ImageType)type + cornerRadious:(CGFloat)cornerRadious + success:(void (^)(UIImage *image))success; + +/// 加载图片不需要成功的回调 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +/// @param cornerRadious 弧度 +- (void)load_setImageImageWithUrl:(NSString *)url + placeholderImage:(NSString *)placeholderImage + type:(ImageType)type + cornerRadious:(CGFloat)cornerRadious; + +/// 加载图片 没有圆角的设置 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage type:(ImageType)type; + +/// 加载图片 没有类型的设置 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage; + +/// 加载图片 回调图片的 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param success 成功了 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage success:(void (^)(UIImage *image))success; +@end + +NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.m b/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.m new file mode 100644 index 00000000..e4231b76 --- /dev/null +++ b/xplan-ios/Base/UI/UIImageView/UIImageView+LoadImage.m @@ -0,0 +1,140 @@ +// +// UIImageView+LoadImage.m +// xplan-ios +// +// Created by 冯硕 on 2021/9/17. +// + +#import "UIImageView+LoadImage.h" +#import + +@implementation UIImageView (LoadImage) + + +/// 加载图片 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +/// @param cornerRadious 弧度 +/// @param success 成功的回调 +- (void)load_setImageImageWithUrl:(NSString *)url + placeholderImage:(NSString *)placeholderImage + type:(ImageType)type + cornerRadious:(CGFloat)cornerRadious + success:(void (^)(UIImage *image))success { + NSMutableString *urlString = [NSMutableString stringWithString:url]; + NSString *configUrl = nil; + switch (type) { + case ImageTypeUserIcon: + { + configUrl = kImageTypeUserIcon; + } + break; + case ImageTypeCornerAvatar: + { + configUrl = kImageTypeCornerAvatar; + } + break; + case ImageTypeRoomFace: + { + configUrl = kImageTypeRoomFace; + } + break; + case ImageTypeUserLibaryDetail: + { + configUrl = kImageTypeUserLibaryDetail; + } + break; + case ImageTypeRoomGift: + { + configUrl = kImageTypeRoomGift; + } + break; + default: + break; + } + if (configUrl) { + + if ([url containsString:@"?"]) { + [urlString appendString:@"|"]; + }else{ + [urlString appendString:@"?"]; + } + [urlString appendString:configUrl]; + } + + if (cornerRadious > 0) { + [urlString appendString:[NSString stringWithFormat:@"|roundPic/radius/%f",cornerRadious]]; + } + + NSString *encodeStr = [self URLEncodedString:urlString]; + + if (placeholderImage.length > 0) { + [self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:[UIImage imageNamed:placeholderImage] options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { + if (success) { + success(image); + } + }]; + }else{ + [self sd_setImageWithURL:[NSURL URLWithString:encodeStr] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { + if (success) { + success(image); + } + }]; + } +} + + +/// 加载图片不需要成功的回调 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +/// @param cornerRadious 弧度 +- (void)load_setImageImageWithUrl:(NSString *)url + placeholderImage:(NSString *)placeholderImage + type:(ImageType)type + cornerRadious:(CGFloat)cornerRadious { + [self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:cornerRadious success:nil]; +} + + +/// 加载图片 没有圆角的设置 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param type 类型 用于设置大小 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage type:(ImageType)type{ + [self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:type cornerRadious:0]; +} + +/// 加载图片 没有类型的设置 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage { + [self load_setImageImageWithUrl:url placeholderImage:placeholderImage type:0 cornerRadious:0]; +} + + +/// 加载图片 回调图片的 +/// @param url 图片的链接地址 +/// @param placeholderImage 站位图 +/// @param success 成功了 +- (void)load_setImageImageWithUrl:(NSString *)url placeholderImage:(NSString *)placeholderImage success:(void (^)(UIImage *image))success{ + [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeholderImage ? [UIImage imageNamed:placeholderImage] : nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { + success(image); + }]; +} + +- (NSString *)URLEncodedString:(NSString *)string +{ + + NSString *encodedString = (NSString *) + CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + (CFStringRef)string, + NULL, + (CFStringRef)@"|", + kCFStringEncodingUTF8)); + + return encodedString; +} + +@end diff --git a/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.h b/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.h new file mode 100644 index 00000000..28f6d928 --- /dev/null +++ b/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.h @@ -0,0 +1,32 @@ +// +// UIImageViewConstant.h +// xplan-ios +// +// Created by 冯硕 on 2021/9/17. +// 存放一些 加载图片 需要做的裁剪的key + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface UIImageViewConstant : NSObject + + +UIKIT_EXTERN NSString * const kImageTypeRoomFace; //房间表情 +UIKIT_EXTERN NSString * const kImageTypeRoomGift; //房间礼物 +UIKIT_EXTERN NSString * const kImageTypeUserIcon; //用户头像60x60 +UIKIT_EXTERN NSString * const kImageTypeUserLibaryDetail;//用户相册大图nil +UIKIT_EXTERN NSString * const kImageTypeCornerAvatar;//圆角图形,会先把图形裁剪成正方形,并且转换为png + + +#pragma mark - 图片相关的 +typedef NS_ENUM(NSUInteger,ImageType){ + ImageTypeRoomFace, //房间表情 + ImageTypeRoomGift, //房间礼物 + ImageTypeUserIcon, //用户头像60x60 + ImageTypeUserLibaryDetail, //用户相册大图 + ImageTypeCornerAvatar, //圆角图形,会先把图形裁剪成正方形,并且转换为png +}; +@end + +NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.m b/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.m new file mode 100644 index 00000000..50ac81e2 --- /dev/null +++ b/xplan-ios/Base/UI/UIImageView/UIImageViewConstant.m @@ -0,0 +1,19 @@ +// +// UIImageViewConstant.m +// xplan-ios +// +// Created by 冯硕 on 2021/9/17. +// + +#import "UIImageViewConstant.h" + +@implementation UIImageViewConstant + + +NSString * const kImageTypeRoomFace = @""; //房间表情 +NSString * const kImageTypeRoomGift = @""; //房间礼物 +NSString * const kImageTypeUserIcon = @"imageMogr2/auto-orient/thumbnail/150x150"; //用户头像150x150 +NSString * const kImageTypeUserLibaryDetail = @""; //用户相册大图nil +NSString * const kImageTypeCornerAvatar = @"imageMogr2/auto-orient/thumbnail/300x300/format/png"; + +@end