自己修改的MBProgressHUD 代码
2016-05-05 15:06
344 查看
+ (MBProgressHUD *)sharedMBProgressHUD { static MBProgressHUD *_sharedHUD = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedHUD = [[MBProgressHUD alloc] initWithView:[UIApplication sharedApplication].keyWindow]; }); return _sharedHUD; }
// // UIViewController+ZYHUD.h // test_HUD_01 // // Created by admin on 4/13/16. // Copyright © 2016 jeffasd. All rights reserved. // #import <UIKit/UIKit.h> #import "MBProgressHUD.h" @interface UIViewController (ZYHUD) @property (nonatomic, strong) MBProgressHUD *hudAddNew; - (void)zyShowHudInView:(UIView *)view hint:(NSString *)hint; - (void)zyHideHud; - (void)zyHideHud:(void(^)())result; - (void)zyShowHint:(NSString *)hint; - (void)zyShowHint:(NSString *)hint DismissAfter:(NSTimeInterval)time; //// 从默认(showHint:)显示的位置再往上(下)yOffset //- (void)showHint:(NSString *)hint yOffset:(float)yOffset; @end
// // UIViewController+ZYHUD.m // test_HUD_01 // // Created by admin on 4/13/16. // Copyright © 2016 jeffasd. All rights reserved. // #import "UIViewController+ZYHUD.h" #import <objc/runtime.h> #import <RACEXTScope.h> #define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) @implementation UIViewController (ZYHUD) - (MBProgressHUD *)hudAddNew{ return objc_getAssociatedObject(self, @selector(hudAddNew)); } - (void)setHudAddNew:(MBProgressHUD *)hudAddNew{ objc_setAssociatedObject(self, @selector(hudAddNew), hudAddNew, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (void)zyShowHudInView:(UIView *)view hint:(NSString *)hint{ self.hudAddNew = [[MBProgressHUD alloc] initWithView:view]; self.hudAddNew.labelText = hint; [view addSubview:self.hudAddNew]; [self.hudAddNew show:YES]; } - (void)zyShowHint:(NSString *)hint { // UIView *view = [[UIApplication sharedApplication].delegate window]; // self.hudAddNew = [MBProgressHUD sharedMBProgressHUD]; // [view addSubview:self.hudAddNew]; // BOOL animated = YES; // [self.hudAddNew show:YES]; // self.hudAddNew.userInteractionEnabled = NO; // self.hudAddNew.labelText = hint; // self.hudAddNew.margin = 10.f; // self.hudAddNew.removeFromSuperViewOnHide = YES; @weakify(self); dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); UIView *view = [[UIApplication sharedApplication].delegate window]; self.hudAddNew = [MBProgressHUD sharedMBProgressHUD]; [view addSubview:self.hudAddNew]; BOOL animated = YES; [self.hudAddNew show:YES]; self.hudAddNew.userInteractionEnabled = NO; self.hudAddNew.labelText = hint; self.hudAddNew.margin = 10.f; self.hudAddNew.removeFromSuperViewOnHide = YES; }); } - (void)zyShowHint:(NSString *)hint DismissAfter:(NSTimeInterval)time { @weakify(self); dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); UIView *view = [[UIApplication sharedApplication].delegate window]; self.hudAddNew = [MBProgressHUD sharedMBProgressHUD]; [view addSubview:self.hudAddNew]; BOOL animated = YES; [self.hudAddNew show:YES]; self.hudAddNew.userInteractionEnabled = NO; self.hudAddNew.labelText = hint; self.hudAddNew.margin = 10.f; self.hudAddNew.removeFromSuperViewOnHide = YES; [self.hudAddNew hide:YES afterDelay:time]; }); } - (void)zyHideHud{ NSLog(@"self class is %@", [self class]); NSLog(@"self is %@", self); // @weakify(self); // dispatch_async(dispatch_get_main_queue(), ^{ // @strongify(self); //// [self.hudAddNew removeFromSuperview]; // [self.hudAddNew hide:YES]; // // }); [self performSelectorOnMainThread:@selector(hidezyHud) withObject:nil waitUntilDone:YES]; } - (void)hidezyHud{ [self.hudAddNew removeFromSuperview]; } - (void)zyHideHud:(void(^)())result{ @weakify(self); dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); [self.hudAddNew removeFromSuperview]; result(); }); } @end
相关文章推荐
- yaffs2文件系统的制作
- myeclipse启动报“java was started but returned exit code=13”
- 使用Maven搭建Struts2框架的开发环境
- FTP学习笔记
- Floyd判圈算法
- Spring 使用@ComponentScan扫描注解包
- <C++精英内参-程序员高效指南>-4搭配VS的好用工具
- 关于在Struts2的Action中使用domain模型接收参数的问题
- JAVA闰年的0229日期问题
- java 的Exception和Error
- C#静态代码检查工具StyleCode -- 初探
- MyEclipse下要给主函数传递参数问题
- C#资深开发组 427769854
- composer 安装yii2 The package is not available in a stable-enough version解决办法
- Java 流(Stream)、文件(File)和IO
- PyCharm添加Python自定义模板
- 谈谈对Spring IOC的理解
- java 计算中缀表达式结果
- .Net中C#的DllImport的用法
- Spring 对数据库操作