一、简要说明
- SVProgressHUD用来显示正在进行的任务的进展情况,用于显示任务加载时的动画,有很多种样式的提示框,非常轻便,容易使用,可用于iOS和tvOS。
二、用法
- 在网络请求、下拉刷新、无限滚动、发送消息时都可以使用SVProgressHUD来展示任务进展情况。
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// time-consuming task
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
三、集成方式
1、通过Cocoapods
- 将 pod 'SVProgressHUD' 添加到Podfile文件中,然后在终端执行命令pod install
- 在要使用的类中引入头文件即可使用SVProgressHUD
#import <SVProgressHUD.h>
2、手动
- 拖拽 SVProgressHUD/SVProgressHUD文件夹到你的项目,把 SVProgressHUD.bundle 添加进 Targets->Build Phases->Copy Bundle Resources,添加 QuartzCore framework 到你的项目。
- 在要使用的类中引入头文件即可使用SVProgressHUD
#import "SVProgressHUD.h"
四、主要功能
1.指示任务的状态
[SVProgressHUD showWithStatus:@"加载中,请稍后。。。"];
2.指示任务的进度
progressValue += 0.1;
[SVProgressHUD showProgress:progressValue status:@"加载中"];
3.HUB隐藏
[SVProgressHUD dismiss];
或者[SVProgressHUD dismissWithDelay:1.0];
4.显示一个提示消息
[SVProgressHUD showErrorWithStatus:@"当前网络不稳定,请稍后重试"];
5.自定义
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
[SVProgressHUD setBackgroundColor:[UIColor blackColor]];
[SVProgressHUD setForegroundColor:[UIColor whiteColor]];
6.通知
6.1 SVProgressHUD通过NSNotificationCenter 注册4份通知,以响应正在显示/消失:
- SVProgressHUDWillAppearNotification 提示框即将出现
- SVProgressHUDDidAppearNotification 提示框已经出现
- SVProgressHUDWillDisappearNotification 提示框即将消失
- SVProgressHUDDidDisappearNotification 提示框已经消失
- 每个通知传递一个userInfo字典,字典中包含HUD的状态字符串(如果有的话),可通过SVProgressHUDStatusUserInfoKey作为键来获取。
6.2 SVProgressHUD还发送通知:
- SVProgressHUDDidReceiveTouchEventNotification当用户触摸整体屏幕上
- SVProgressHUDDidTouchDownInsideNotification当用户直接在HUD接触。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:)
name:SVProgressHUDWillAppearNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:)
name:SVProgressHUDDidAppearNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:)
name:SVProgressHUDWillDisappearNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:)
name:SVProgressHUDDidDisappearNotification
object:nil];
}
五、当前版本
`2.0-beta8`