From ca5db3f985545d3f3f41d8c4ced443a1971cc723 Mon Sep 17 00:00:00 2001 From: wujunyang Date: Sat, 9 Jul 2016 10:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5MBProgressHUD=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MobileProject.xcodeproj/project.pbxproj | 8 ++ .../Expand/Category/Other/MBProgressHUD+MP.h | 133 ++++++++++++++++++ .../Expand/Category/Other/MBProgressHUD+MP.m | 128 +++++++++++++++++ MobileProject/Expand/Macros/Macros.h | 25 +++- 4 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 MobileProject/Expand/Category/Other/MBProgressHUD+MP.h create mode 100644 MobileProject/Expand/Category/Other/MBProgressHUD+MP.m diff --git a/MobileProject.xcodeproj/project.pbxproj b/MobileProject.xcodeproj/project.pbxproj index 4830d8e..e9ccbe6 100644 --- a/MobileProject.xcodeproj/project.pbxproj +++ b/MobileProject.xcodeproj/project.pbxproj @@ -70,6 +70,8 @@ 341094031D0E982100A8D63F /* JSPatchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 341094011D0E982100A8D63F /* JSPatchViewController.m */; settings = {ASSET_TAGS = (); }; }; 341094061D0EAF0D00A8D63F /* demo.js in Resources */ = {isa = PBXBuildFile; fileRef = 341094051D0EAF0D00A8D63F /* demo.js */; settings = {ASSET_TAGS = (); }; }; 341094071D0EAF0D00A8D63F /* demo.js in Resources */ = {isa = PBXBuildFile; fileRef = 341094051D0EAF0D00A8D63F /* demo.js */; settings = {ASSET_TAGS = (); }; }; + 341CA90F1D3097AF008B85D3 /* MBProgressHUD+MP.m in Sources */ = {isa = PBXBuildFile; fileRef = 341CA90E1D3097AF008B85D3 /* MBProgressHUD+MP.m */; settings = {ASSET_TAGS = (); }; }; + 341CA9101D3097AF008B85D3 /* MBProgressHUD+MP.m in Sources */ = {isa = PBXBuildFile; fileRef = 341CA90E1D3097AF008B85D3 /* MBProgressHUD+MP.m */; settings = {ASSET_TAGS = (); }; }; 34420CB91D0FAC9E007D1AAC /* AdvertiseHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */; settings = {ASSET_TAGS = (); }; }; 34420CBA1D0FAC9E007D1AAC /* AdvertiseHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */; settings = {ASSET_TAGS = (); }; }; 34420CBD1D0FAD10007D1AAC /* AdvertiseView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34420CBC1D0FAD10007D1AAC /* AdvertiseView.m */; settings = {ASSET_TAGS = (); }; }; @@ -815,6 +817,8 @@ 341094001D0E982100A8D63F /* JSPatchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPatchViewController.h; sourceTree = ""; }; 341094011D0E982100A8D63F /* JSPatchViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSPatchViewController.m; sourceTree = ""; }; 341094051D0EAF0D00A8D63F /* demo.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = demo.js; sourceTree = ""; }; + 341CA90D1D3097AF008B85D3 /* MBProgressHUD+MP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MBProgressHUD+MP.h"; sourceTree = ""; }; + 341CA90E1D3097AF008B85D3 /* MBProgressHUD+MP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MBProgressHUD+MP.m"; sourceTree = ""; }; 34420CB71D0FAC9E007D1AAC /* AdvertiseHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseHelper.h; sourceTree = ""; }; 34420CB81D0FAC9E007D1AAC /* AdvertiseHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AdvertiseHelper.m; sourceTree = ""; }; 34420CBB1D0FAD10007D1AAC /* AdvertiseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AdvertiseView.h; sourceTree = ""; }; @@ -1688,6 +1692,8 @@ 340BCD5D1D0F027F0093CC7D /* UIViewController+Swizzle.m */, 34E08A571C3BEA89005C6CA3 /* GVUserDefaults+BBProperties.h */, 34E08A581C3BEA89005C6CA3 /* GVUserDefaults+BBProperties.m */, + 341CA90D1D3097AF008B85D3 /* MBProgressHUD+MP.h */, + 341CA90E1D3097AF008B85D3 /* MBProgressHUD+MP.m */, ); path = Other; sourceTree = ""; @@ -3894,6 +3900,7 @@ 34E08A6C1C3BFB90005C6CA3 /* NSObject+AssociatedObject.m in Sources */, 34E08A6D1C3BFB90005C6CA3 /* UIView+ViewController.m in Sources */, 34E08A6E1C3BFB90005C6CA3 /* UIViewController+BackButtonItemTitle.m in Sources */, + 341CA9101D3097AF008B85D3 /* MBProgressHUD+MP.m in Sources */, 34E08A6F1C3BFB90005C6CA3 /* UIViewController+Visible.m in Sources */, 34E08A701C3BFB90005C6CA3 /* MKMapView+ZoomLevel.m in Sources */, 34E08A711C3BFB90005C6CA3 /* YTKChainRequestAgent.m in Sources */, @@ -4257,6 +4264,7 @@ 340BCD241D0F011A0093CC7D /* LogInApi.m in Sources */, 34E8941C1C3B9A03001327C8 /* UITextView+PinchZoom.m in Sources */, 34E894351C3B9A03001327C8 /* UIViewController+DDPopUpViewController.m in Sources */, + 341CA90F1D3097AF008B85D3 /* MBProgressHUD+MP.m in Sources */, 34E893761C3B9A03001327C8 /* NSDate+CupertinoYankee.m in Sources */, 3452EB8B1D1A8BF00001732E /* AppDelegate.m in Sources */, 34E894301C3B9A03001327C8 /* UIView+Visuals.m in Sources */, diff --git a/MobileProject/Expand/Category/Other/MBProgressHUD+MP.h b/MobileProject/Expand/Category/Other/MBProgressHUD+MP.h new file mode 100644 index 0000000..7625c7f --- /dev/null +++ b/MobileProject/Expand/Category/Other/MBProgressHUD+MP.h @@ -0,0 +1,133 @@ +// +// MBProgressHUD+MP.h +// MobileProject +// 当引入MBProgressHUD时把下面的代码开放出来 +// 使用如下: +// [MBProgressHUD showIconMessage:@"默认图,X秒后自动消失" ToView:self.view RemainTime:3]; +// [MBProgressHUD showMessage:@"纯文字,不自动消失" ToView:self.view]; 关掉则用:[MBProgressHUD hideHUD];//使用此方法进行隐藏 +// MBProgressHUD *hud = [MBProgressHUD showProgressToView:nil ProgressModel:MBProgressHUDModeDeterminate Text:@"loading"]; 隐藏:[hud hide:YES]; +// [MBProgressHUD showAutoMessage:@"自动消失"]; +// [MBProgressHUD showSuccess:@"下载完成" ToView:self.view]; +// [MBProgressHUD showError:@"下载失败" ToView:self.view]; +// Created by wujunyang on 16/7/9. +// Copyright © 2016年 wujunyang. All rights reserved. +// + +#import + + +//#import "MBProgressHUD.h" +// +//@interface MBProgressHUD (MP) +// +// +///** +// * 自定义图片的提示,1s后自动消息 +// * +// * @param text 要显示的文字 +// * @param icon 图片地址(建议不要太大的图片) +// * @param view 要添加的view +// */ +//+ (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view; +// +// +///** +// * 自动消失成功提示,带默认图 +// * +// * @param success 要显示的文字 +// * @param view 要添加的view +// */ +//+ (void)showSuccess:(NSString *)success ToView:(UIView *)view; +// +// +///** +// * 自动消失错误提示,带默认图 +// * +// * @param error 要显示的错误文字 +// * @param view 要添加的View +// */ +//+ (void)showError:(NSString *)error ToView:(UIView *)view; +// +// +///** +// * 文字+菊花提示,不自动消失 +// * +// * @param message 要显示的文字 +// * @param view 要添加的View +// * +// * @return MBProgressHUD +// */ +//+ (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view; +// +// +///** +// * 快速显示一条提示信息 +// * +// * @param showAutoMessage 要显示的文字 +// */ +//+ (void)showAutoMessage:(NSString *)message; +// +// +///** +// * 自动消失提示,无图 +// * +// * @param message 要显示的文字 +// * @param view 要添加的View +// */ +//+ (void)showAutoMessage:(NSString *)message ToView:(UIView *)view; +// +// +///** +// * 自定义停留时间,有图 +// * +// * @param message 要显示的文字 +// * @param view 要添加的View +// * @param time 停留时间 +// */ +//+(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time; +// +// +///** +// * 自定义停留时间,无图 +// * +// * @param text 要显示的文字 +// * @param view 要添加的View +// * @param time 停留时间 +// */ +//+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time; +// +// +///** +// * 加载视图 +// * +// * @param view 要添加的View +// */ +//+ (void)showLoadToView:(UIView *)view; +// +// +///** +// * 进度条View +// * +// * @param view 要添加的View +// * @param model 进度条的样式 +// * @param text 显示的文字 +// * +// * @return 返回使用 +// */ +//+ (MBProgressHUD *)showProgressToView:(UIView *)view ProgressModel:(MBProgressHUDMode)model Text:(NSString *)text; +// +// +///** +// * 隐藏ProgressView +// * +// * @param view superView +// */ +//+ (void)hideHUDForView:(UIView *)view; +// +// +///** +// * 快速从window中隐藏ProgressView +// */ +//+ (void)hideHUD; +// +//@end diff --git a/MobileProject/Expand/Category/Other/MBProgressHUD+MP.m b/MobileProject/Expand/Category/Other/MBProgressHUD+MP.m new file mode 100644 index 0000000..02a2ed4 --- /dev/null +++ b/MobileProject/Expand/Category/Other/MBProgressHUD+MP.m @@ -0,0 +1,128 @@ +// +// NSObject+MP.m +// MobileProject +// +// Created by wujunyang on 16/7/9. +// Copyright © 2016年 wujunyang. All rights reserved. +// + +#import "MBProgressHUD+MP.h" + +//@implementation MBProgressHUD (MP) +// +//#pragma mark 显示错误信息 +//+ (void)showError:(NSString *)error ToView:(UIView *)view{ +// [self showCustomIcon:@"error.png" Title:error ToView:view]; +//} +// +//+ (void)showSuccess:(NSString *)success ToView:(UIView *)view +//{ +// [self showCustomIcon:@"success.png" Title:success ToView:view]; +//} +// +//#pragma mark 显示一些信息 +//+ (MBProgressHUD *)showMessage:(NSString *)message ToView:(UIView *)view { +// if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; +// // 快速显示一个提示信息 +// MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; +// hud.labelText = message; +// // 隐藏时候从父控件中移除 +// hud.removeFromSuperViewOnHide = YES; +// // YES代表需要蒙版效果 +// hud.dimBackground = YES; +// return hud; +//} +// +////加载视图 +//+(void)showLoadToView:(UIView *)view{ +// [self showMessage:@"Loading..." ToView:view]; +//} +// +// +///** +// * 进度条View +// */ +//+ (MBProgressHUD *)showProgressToView:(UIView *)view ProgressModel:(MBProgressHUDMode)model Text:(NSString *)text{ +// if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; +// MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; +// hud.mode = model; +// hud.labelText = text; +// return hud; +//} +// +// +////快速显示一条提示信息 +//+ (void)showAutoMessage:(NSString *)message{ +// +// [self showAutoMessage:message ToView:nil]; +//} +// +// +////自动消失提示,无图 +//+ (void)showAutoMessage:(NSString *)message ToView:(UIView *)view{ +// [self showMessage:message ToView:view RemainTime:0.9 Model:MBProgressHUDModeText]; +//} +// +////自定义停留时间,有图 +//+(void)showIconMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{ +// [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeIndeterminate]; +//} +// +////自定义停留时间,无图 +//+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time{ +// [self showMessage:message ToView:view RemainTime:time Model:MBProgressHUDModeText]; +//} +// +//+(void)showMessage:(NSString *)message ToView:(UIView *)view RemainTime:(CGFloat)time Model:(MBProgressHUDMode)model{ +// +// if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; +// // 快速显示一个提示信息 +// MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; +// hud.labelText = message; +// //模式 +// hud.mode = model; +// // 隐藏时候从父控件中移除 +// hud.removeFromSuperViewOnHide = YES; +// // YES代表需要蒙版效果 +// hud.dimBackground = YES; +// // 隐藏时候从父控件中移除 +// hud.removeFromSuperViewOnHide = YES; +// // X秒之后再消失 +// [hud hide:YES afterDelay:time]; +//} +// +//+ (void)showCustomIcon:(NSString *)iconName Title:(NSString *)title ToView:(UIView *)view +//{ +// if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; +// // 快速显示一个提示信息 +// MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; +// hud.labelText = title; +// // 设置图片 +// if ([iconName isEqualToString:@"error.png"] || [iconName isEqualToString:@"success.png"]) { +// hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", iconName]]]; +// }else{ +// hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:iconName]]; +// } +// // 再设置模式 +// hud.mode = MBProgressHUDModeCustomView; +// +// // 隐藏时候从父控件中移除 +// hud.removeFromSuperViewOnHide = YES; +// +// // 1秒之后再消失 +// [hud hide:YES afterDelay:0.9]; +//} +// +//+ (void)hideHUDForView:(UIView *)view +//{ +// if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window; +// [self hideHUDForView:view animated:YES]; +//} +// +//+ (void)hideHUD +//{ +// [self hideHUDForView:nil]; +//} +// +// +//@end diff --git a/MobileProject/Expand/Macros/Macros.h b/MobileProject/Expand/Macros/Macros.h index 5e66b93..5e1e48b 100644 --- a/MobileProject/Expand/Macros/Macros.h +++ b/MobileProject/Expand/Macros/Macros.h @@ -51,11 +51,11 @@ #define DSystemVersion ([[[UIDevice currentDevice] systemVersion] doubleValue]) #define SSystemVersion ([[UIDevice currentDevice] systemVersion]) -// 是否IOS7 +// 是否大于等于IOS7 #define isIOS7 ([[[UIDevice currentDevice]systemVersion]floatValue] >= 7.0) // 是否IOS6 #define isIOS6 ([[[UIDevice currentDevice]systemVersion]floatValue] < 7.0) -// +// 是否大于等于IOS8 #define isIOS8 ([[[UIDevice currentDevice]systemVersion]floatValue] >=8.0) // 是否iPad #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) @@ -83,6 +83,13 @@ //Library/Caches 文件路径 #define FilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]) +//获取temp +#define kPathTemp NSTemporaryDirectory() +//获取沙盒 Document +#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] +//获取沙盒 Cache +#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] + //在Main线程上运行 #define DISPATCH_ON_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock); @@ -92,6 +99,8 @@ //更新UI //}) + + //在Global Queue上运行 #define DISPATCH_ON_GLOBAL_QUEUE_HIGH(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), globalQueueBlocl); #define DISPATCH_ON_GLOBAL_QUEUE_DEFAULT(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl); @@ -103,3 +112,15 @@ //异步耗时任务 //}) + +//弱引用/强引用 可配对引用在外面用MPWeakSelf(self),block用MPStrongSelf(self) 也可以单独引用在外面用MPWeakSelf(self) block里面用weakself +#define MPWeakSelf(type) __weak typeof(type) weak##type = type; +#define MPStrongSelf(type) __strong typeof(type) type = weak##type; + + + + + + + +