[翻译] SVProgressHUD

简介:

SVProgressHUD

https://github.com/TransitApp/SVProgressHUD

 

SVProgressHUD is a clean and easy-to-use HUD meant to display the progress of an ongoing task.

SVProgressHUD 是一个清新易用的指示器,用来指示正在执行的任务。

 

Installation

From CocoaPods CocoaPods安装

I'm not a big fan of CocoaPods, so tend to not keep it updated. If you really want to use SVProgressHUD with CocoaPods, I suggest you use pod 'SVProgressHUD', :head to pull from the master branch directly. I'm usually careful about what I push there and is the version I use myself in all my projects.

Manually 手动安装

  • Drag the SVProgressHUD/SVProgressHUD folder into your project.
  • Add the QuartzCore framework to your project.

Usage 使用

(see sample Xcode project in /Demo)

SVProgressHUD is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call [SVProgressHUD method]).

SVProgressHUD 是单例模式(也就是说你只需要调用[SVProgressHUD method]即可)

Use SVProgressHUD wisely! Only use it if you absolutely need to perform a task before taking the user forward. Bad use case examples: pull to refresh, infinite scrolling, sending message.

请明智的使用SVProgressHUD!仅仅当你确保绝对要执行一项任务了。以下是不当的使用情形:下拉刷新,发送消息,无限滚动

Using SVProgressHUD in your app will usually look as simple as this (using Grand Central Dispatch):

请以以下的方式使用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]; }); }); 

Showing the HUD 显示指示器

You can show the status of indeterminate tasks using one of the following:

你可以用以下的方式来指示你在做什么:

+ (void)show; + (void)showWithMaskType:(SVProgressHUDMaskType)maskType; + (void)showWithStatus:(NSString*)string; + (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType; 

If you'd like the HUD to reflect the progress of a task, use one of these:

如果你想显示任务的进度情况,用下面的方法:

+ (void)showProgress:(CGFloat)progress; + (void)showProgress:(CGFloat)progress status:(NSString*)status; + (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType; 

Dismissing the HUD 隐藏指示器

It can be dismissed right away using:

你可以用以下方法隐藏指示器:

+ (void)dismiss; 

If you'd like to stack HUDs, you can balance out every show call using:

如果你想用栈的方式存储按照顺序来显示,你可以依次调用以下方法:

+ (void)popActivity; 

The HUD will get dismissed once the popActivity calls will match the number of show calls.

这个指示器会依照顺序依次消失

Or show a confirmation glyph before before getting dismissed 1 second later using:

或者按照标志位延时1s钟消失:

+ (void)showSuccessWithStatus:(NSString*)string; + (void)showErrorWithStatus:(NSString *)string; + (void)showImage:(UIImage*)image status:(NSString*)string; // use 28x28 pngs 

 

Customization

SVProgressHUD can be customized via the following methods:

SVProgressHUD 可以用以下方式定制:

+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor] + (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor] + (void)setRingThickness:(CGFloat)width; // default is 4 pt + (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] + (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Glyphish + (void)setErrorImage:(UIImage*)image; // default is bundled error image from Glyphish 

 

Notifications

SVProgressHUD posts four notifications via NSNotificationCenter in response to being shown/dismissed:

SVProgressHUD 通过通知中心发送4种通知来显示/隐藏:

  • SVProgressHUDWillAppearNotification when the show animation starts
  • SVProgressHUDDidAppearNotification when the show animation completes
  • SVProgressHUDWillDisappearNotification when the dismiss animation starts
  • SVProgressHUDDidDisappearNotification when the dismiss animation completes

Each notification passes a userInfo dictionary holding the HUD's status string (if any), retrievable viaSVProgressHUDStatusUserInfoKey.

每一个通知都传递一个userInfo字典来装载HUD状态值,其值可以通过viaSVProgressHUDStatusUserInfoKey来获取。

SVProgressHUD also posts SVProgressHUDDidReceiveTouchEventNotification when users touch on the screen. For this notification userInfo is not passed but the object parameter contains the UIEvent that related to the touch.

SVProgressHUD当用户触摸屏幕的时候,也能发送SVProgressHUDDidReceiveTouchEventNotification。这种通知方式呢,并没有把userInfo当做参数来传递,取而代之的是object对象,包含了这个触摸的事件。

目录
相关文章
JAVA 将一个对象的所有字段值 赋给另一个 对象
JAVA 将一个对象的所有字段值 赋给另一个 对象
1161 0
JAVA 将一个对象的所有字段值 赋给另一个 对象
|
弹性计算 数据安全/隐私保护 计算机视觉
|
JavaScript 内存技术
Vue 安装vue-element-admin启动报错error:0308010C:digital envelope routines::unsupported
Vue 安装vue-element-admin启动报错error:0308010C:digital envelope routines::unsupported
318 0
|
Cloud Native 关系型数据库 分布式数据库
|
12月前
|
Oracle 关系型数据库 MySQL
Oracle linux 8 二进制安装 MySQL 8.4企业版
Oracle linux 8 二进制安装 MySQL 8.4企业版
537 1
实验深度理解Go中try...catch...的panic、defer、recover用法
文章通过实验代码演示了Go语言中如何使用panic、defer和recover函数来模拟try...catch...的异常处理机制,并详细解释了每个函数的作用和在异常处理中的使用场景。
290 0
|
前端开发 JavaScript 架构师
了解微前端,深入前端架构的前世今生
该文章深入探讨了微前端架构的起源、发展及其解决的问题,并详细讲解了微前端在现代Web应用中的实现方式与优势,帮助读者理解微前端的设计理念和技术细节。
|
开发框架 前端开发 Linux
Go语言实战框架,GoFly全栈开发社区的Go快速开发框架简介与阿里服务器部署说明
GoFly中后台框架永久开源可商用。api文档管理并一键生成api接口代码,一键生成 CRUD前后端代码, GoFly快速开发框架是一款基于Go语言的 Gin和 Vue3的Arco Design的快速后台开发框架,基于JWT接口验证和Auth验证的权限管理系统,附件管理系统,天生支持saas架构。可打包部署在阿里云Linux系统上。
1259 1
|
搜索推荐 开发者
熊猫比分-专业体育赛事直播app/网页搭建
体育赛事直播APP已成为体育迷观看和讨论赛事的重要渠道。其核心功能包括:1) 实时直播,支持转播、录播、回放,确保低延迟、高流畅度和优质画质;2) 比分数据分析,提供首发阵容、历史对战等信息;3) 用户互动,支持评论、打赏及私聊;4) 主播中心,允许用户申请成为主播并获平台支持。
|
消息中间件 缓存 并行计算
每秒钟承载600万订单级别的无锁并行计算框架 Disruptor学习
每秒钟承载600万订单级别的无锁并行计算框架 Disruptor学习
322 0

热门文章

最新文章

下一篇
开通oss服务