KVNProgress 2.3.5

KVNProgress 2.3.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2018年10月

Kevin HirschKevin HirschKevin HirschErdem维护。



KVNProgress

Coverage Status Build Status Twitter: @kevinh6113 License: MIT Version Cocoapods

KVNProgress是一个可完全定制的进度HUD,可以是全屏也可以不是。


在您的应用中使用KVNProgress?

如果您在使用KVNProgress,我很乐意听到您的反馈!😀
请确保在这里自豪地大喊一声 这里👍
Assisto和12,021*个正在使用KVNProgress并不断增加的应用...
* via CocoaPods

目录


预览

基本界面
Indeterminate progress Determinate progress Success HUD Error HUD
全屏界面
Full screen indeterminate progress Full screen determinate progress Full screen success HUD Full screen error HUD
自定义界面示例

优点

  • 支持全屏展示
  • 使用 UIMotionEffect
  • 支持所有方向
  • 支持iPad
  • 支持文本更新动画
  • 支持成功勾选动画
  • 文档完善
  • 完全可定制
    • 颜色
    • 字体
    • 圆圈大小和厚度
    • 模糊或纯色背景

演示

这是该项目中演示应用的视频。如果您想亲自尝试,只需下载/检出此存储库并在Xcode中启动项目即可。

Demo video

安装

Cocoapods

CocoaPods 推荐使用 KVNProgress。

  1. 在您的 Podfile 中添加 pod 'KVNProgress'
  2. 运行 pod install 以安装 pod。
  3. 使用 #import <KVNProgress/KVNProgress.h> 将 KVNProgress 包含在任何需要它的地方。

源文件

  1. 下载最新版本的代码版本,或将存储库作为 git 子模块添加到您的 git 追踪项目中。
  2. 从存档中将 分类资源 目录拖放到您项目的导航器中。如果您在项目外部解压了代码存档,请确保在询问时选择 复制项目
  3. 使用 #import <KVNProgress/KVNProgress.h> 将 KVNProgress 包含在任何需要它的地方。

用法

请查看提供的示例应用程序,了解您如何使用这些组件的许多示例。

基础

KVNProgress HUD 会阻止用户与其后面的界面交互。您可以自定义 HUD 的颜色、字体和大小。

请将下面的导入语句添加到文件顶部或前缀头部

#import <KVNProgress/KVNProgress.h>

进度

不确定进度

要显示不确定进度

[KVNProgress show];

// Adds a status below the circle
[KVNProgress showWithStatus:@"Loading"];

// Adds the HUD to a certain view instead of main window
[KVNProgress showWithStatus:@"Loading"
                     onView:view];

要实时更改状态(动画效果)

 [KVNProgress updateStatus:@"New status"];

确定进度

要显示确定进度并随时间更改其值

// Progress has to be between 0 and 1
[KVNProgress showProgress:0.5f];

// Adds a status below the progress
[KVNProgress showProgress:0.5f
                   status:@"Loading"];

// Adds the HUD to a certain view instead of main window
[KVNProgress showProgress:0.5f
                   status:@"Loading"
                   onView:view];

// Updates the progress
[KVNProgress updateProgress:0.75f
                   animated:YES];

停止按钮

您可以在进度 HUD 中添加停止按钮。为此,您需要使用 KVNProgressConfiguration(请参见下面的文档)。您只需要做以下操作

KVNProgressConfiguration *configuration = [KVNProgressConfiguration defaultConfiguration];
configuration.showStop = YES;
configuration.tapBlock = ^(KVNProgress *progressView) {
	// Do what you want
	[KVNProgress dismiss];
};

[KVNProgress setConfiguration:configuration];

tapBlock 会在用户点击 HUD 时执行。如果没有指定 tapBlock,则 showStop 将不会激活!

您可以根据需要自定义停止按钮的大小。默认为圆形大小的30%。

configuration.stopRelativeHeight = 0.3f;
configuration.stopColor = [UIColor whiteColor];

关闭

完成任务后关闭

// Dismiss
[KVNProgress dismiss];

如有必要,您可以使用

// Dismiss
[KVNProgress dismissWithCompletion:^{
   // Things you want to do after the HUD is gone.
}];

为什么?

因为即使调用dismiss,KVNProgress也会保持可见一段时间。这是为了确保用户有足够的时间看到HUD,如果在调用show之后立即调用dismiss。在dismissWithCompletion中的完成块(在主线程上)在HUD完全关闭后被调用。这个最小显示时间是定义在KVNProgressConfiguration对象中(见下文)。默认值是0.3秒。

成功/错误

显示带有勾号的成功HUD

[KVNProgress showSuccess];

// Or
[KVNProgress showSuccessWithStatus:@"Success"];

// Adds the HUD to a certain view instead of main window
[KVNProgress showSuccessWithStatus:@"Success"
                            onView:view];

显示带有叉号的错误HUD

[KVNProgress showError];

// Or
[KVNProgress showErrorWithStatus:@"Error"];

// Adds the HUD to a certain view instead of main window
[KVNProgress showErrorWithStatus:@"Error"
                          onView:view];

成功和错误都自动关闭。如果您希望在关闭后执行某些操作,可以使用以completion为最后参数的上述方法:showSuccessWithCompletion:showSuccessWithStatus:completion:showSuccessWithStatus:onView:completion:showErrorWithCompletion:showErrorWithStatus:completion:showErrorWithStatus:onView:completion:

自定义

KVNProgress的外观非常可定制。如果缺少某些功能或可以添加功能,请随时提出。

KVNProgressConfiguration

您可以使用KVNProgressConfiguration在您的应用UI设置中配置您的HUD UI。下面是如何简单地设置HUD的默认配置的示例

[KVNProgress setConfiguration:[KVNProgressConfiguration defaultConfiguration]];

注意,如果您只需要默认配置,上述代码是不必要的。如果您没有设置配置,则将使用默认配置;)

以下是一个完整的自定义配置示例

 KVNProgressConfiguration *configuration = [[KVNProgressConfiguration alloc] init];

  configuration.statusColor = [UIColor whiteColor];
  configuration.statusFont = [UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f];
  configuration.circleStrokeForegroundColor = [UIColor whiteColor];
  configuration.circleStrokeBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.3f];
  configuration.circleFillBackgroundColor = [UIColor colorWithWhite:1.0f alpha:0.1f];
  configuration.backgroundFillColor = [UIColor colorWithRed:0.173f green:0.263f blue:0.856f alpha:0.9f];
  configuration.backgroundTintColor = [UIColor colorWithRed:0.173f green:0.263f blue:0.856f alpha:1.0f];
  configuration.successColor = [UIColor whiteColor];
  configuration.errorColor = [UIColor whiteColor];
  configuration.stopColor = [UIColor whiteColor];
  configuration.circleSize = 110.0f;
  configuration.lineWidth = 1.0f;
  configuration.fullScreen = NO;
  configuration.showStop = YES;
  configuration.stopRelativeHeight = 0.4f;

configuration.tapBlock = ^(KVNProgress *progressView) {
  // Do something you want to do when the user tap on the HUD
  // Does nothing by default
};

// You can allow user interaction for behind views but you will losse the tapBlock functionnality just above
// Does not work with fullscreen mode
// Default is NO
configuration.allowUserInteraction = NO;

  [KVNProgress setConfiguration:configuration];

如果您未指定配置的某些属性,它们将自动设置为默认值。

触觉反馈

您可以通过以下操作启用错误和成功的触觉反馈:

KVNProgressConfiguration *configuration = [[KVNProgressConfiguration alloc] init];

if (@available(iOS 10, *)) {
	configuration.enableUIFeedback = YES;
}

显示时间

为了避免用户看到闪烁的HUD或由于太早取消显示而完全看不到,HUD将至少显示一段短时间。

您可以通过在KVNProgressConfiguration中更改以下3个属性来达到这个效果

  • minimumDisplayTime其默认值为0.3秒。处理所有除了成功和错误之外的HUD。
  • minimumSuccessDisplayTime其默认值为2.0秒。处理所有成功的HUD。
  • minimumErrorDisplayTime其默认值为1.3秒。处理所有错误的HUD。

已知问题

  • alertView:clickedButtonAtIndex: 时显示 HUD 会导致未定义的行为,有时可能使 HUD 无法显示(#29 - 问题解决注释)。取而代之的是,调用 HUD 在 alertView:didDismissWithButtonIndex: 上以确保在显示 HUD 之前完全关闭 UIAlertView

待完成

  • 使用实时模糊效果

需求

  • Xcode 6
  • iOS 7
  • ARC
  • 框架
    • QuartzCore
    • GLKit

许可证

本项目受MIT许可证的约束。欲了解更多信息,请参阅LICENSE文件。

致谢

KVNProgress受到了MRProgress UI的启发。

KVNProgress是为了整合我在从事的项目:Assisto,并将随需求更新和发现的问题及时修复,以保持其最新状态。

我在Pinch工作。

欢迎在Twitter上关注我 @kevinh6113

享受吧!:)