ANActivityIndicatorView
ANActivityIndicatorView 是一个预构建的指示器动画库,基于 gontovnik 的 DGActivityIndicatorView 和 GTMYang 的 GTMActivityIndicatorView,并受到 loaders.css(CONNOR ATHERTON)的启发。
我为什么将 ANActivityIndicatorView 放在一个单独的仓库中?
首先,我并不是想获得所有这个项目的荣誉。我并没有为 gotnovik 的作品和 GTMYang 的作品做出什么值得称道的事情。
那么,为什么我要将 ANActivityIndicatorView 放在一个单独的仓库中呢?
看起来 gotnovik 没有更新他的仓库,而 GTMYang 的仓库集中关注于与我的使用方法略有不同的用法。
一般差异
与 DGActivityIndicatorView 之间的区别
- 使用 Swift 实现
在GTMActivityIndicatorView之间
- 使用Swift 4实现
- 提供了预构建的指示器动画,使用GTMActivityIndicatorView时,您需要手动将动画添加到您的项目中。
新增功能
- 自定义动画结构(类似于NSNotification.Name的结构体)。
- 自定义加载信息边距。
示例
查看预构建动画类型部分,查看动画类型。
要求
- XCode 9.x或更高版本
- Swift 4.x
- iOS 10.0或更高版本
安装
CocoaPods
pod 'ANActivityIndicator'手动安装
- 下载仓库。
作为框架
- 将
ANActivityIndicator和Source文件夹复制到您的项目目录。 - 将
[项目目录]/ANActivityIndicator/ANActivityIndicator.xcodeproj添加到您的“工作区”中。 - 在
项目设置 -> 一般中,将ANActivityIndicator.framework添加到嵌入式二进制文件和链接框架和库。
作为子项目
- 将
ANActivityIndicator和Source文件夹复制到您的项目目录。 - 将
ANActivityIndicator/ANActivityIndicator.xcodeproj添加到您的“项目”中。
作为代码
- 将
ANActivityIndicator和Source文件夹复制到您的工作区/项目目录。 - 将
[工作区/项目目录]/Source文件夹的内容添加到您的工作区/项目。
用途
导入
如果您作为框架或子项目安装,首先
import ANActivityIndicator初始化
查看
let indicator = ANActivityIndicatorView.init(
frame: CGrect,
animationType: ANAnimationIndicatorType,
color: UIColor,
padding: CGFloat)
aView.addSubview(indicator)对于初始化全屏,请参考显示/隐藏指示器 -> 全屏部分。
显示/隐藏指示器
显示ANActivityIndicator有两种方式
查看
let indicator = ANActivityIndicatorView.init(...)
indicator.startAnimating()
indicator.stopAnimating()全屏
您可以在每个类中显示全屏指示器
在UIViewController或其子类中
//default
showIndicator()
hideIndicator()//custom
showIndicator(
CGSize,
message: String,
messageFont: UIFont,
messageTopMargin: CGFloat,
animationType: ANActivityIndicatorAnimationType,
color: UIColor,
padding: CGFloat,
displayTimeThreshold: TimeIntervalInNanoseconds,
minimumDisplayTime: TimeIntervalInNanoseconds)
hideIndicator()在每一类中
//default
ANActivityIndicatorPresenter.shared.showIndicator()
ANActivityIndicatorPresenter.shared.hideIndicator()//custom
ANActivityIndicatorPresenter.shared.showIndicator(
CGSize,
message: String,
messageFont: UIFont,
messageTopMargin: CGFloat,
animationType: ANActivityIndicatorAnimationType,
color: UIColor,
padding: CGFloat,
displayTimeThreshold: TimeIntervalInNanoseconds,
minimumDisplayTime: TimeIntervalInNanoseconds)
ANActivityIndicatorPresenter.shared.hideIndicator()预置动画类型
以下是预置动画列表。您可以在示例部分查看它们的外观。(按编号排序)
- .audioEqualizer
- .ballBeat
- .ballClipRotate
- .ballClipRotateMultiple
- .ballClipRotatePulse
- .ballGridBeat
- .ballGridPulse
- .ballPulse
- .ballPulseRise
- .ballPulseSync
- .ballRotate
- .ballRotateChase
- .ballScale
- .ballScaleMultiple
- .ballScaleRipple
- .ballScaleRippleMultiple
- .ballSpinFadeLoader
- .ballTrianglePath
- .ballZigZag
- .ballZigZagDeflect
- .blank
- .cubeTransition
- .lineScale
- .lineScaleParty
- .lineScalePulseOut
- .lineScalePulseOutRapid
- .lineSpinFadeLoader
- .orbit
- .pacman
- .semiCircleSpin
- .squareSpin
- .triangleSkewSpin
自定义动画
ANActivityIndicator 拥有类似于 NSNotification.Name 的自定义动画结构。
- 首先创建一个继承自
ANActivityIndicatorAnimation协议的类
class CustomIndicatorAnimation : ANActivityIndicatorAnimation{
required init() { }
func setUpAnimation(in layer: CALayer, size: CGSize, color: UIColor) {
......
//implement your animation
//to learn how to implement, check example project or source codes.
.....
}
}- 然后为您的自定义动画添加
ANActivityIndicatorAnimationType
extension ANActivityIndicatorAnimationType{
public static let customIndicatorAnimation = ANActivityIndicatorAnimationType.init(animation: CustomIndicatorAnimation.self)
}- 现在您可以通过其类型调用您的自定义动画
ANActivityIndicatorAnimationType.customIndicatorAnimation默认值
- 动画类型
ANActivityIndicatorAnimationType.ballSpinFadeLoader- 指示器颜色
UIColor.white- 指示器内边距
CGFloat = 0- 消息
String = ""- 消息字体
UIFont.boldSystemFont(ofSize: 20)- 指示器与消息的边距
CGFloat = 8- 显示时间阈值
默认时间,必须在调用 startAnimating() 和 stopAnimating() 之间实际显示 UI 阻塞器。应考虑活动的最短持续时间是否值得显示给用户。如果活动在时间阈值之前结束,则不会显示。
CGFloat = 0- 最小显示时间
UI阻断器默认最小显示时间。其主要目的是避免闪烁显示和隐藏过快。例如,将其设置为200ms将强制UI阻断器至少显示这么长时间(无论是否提前调用stopAnimating())。
CGFloat = 0- 全屏指示器默认大小
CGSize.init(width: 60, height: 60)许可证
本项目采用MIT许可证。请查阅LICENSE文件。
贡献
非常欢迎任何贡献。请阅读CONTRIBUTING文件。
- 确保完成
pull request模板。 - 确保你的代码通过TravisCI。
(尚未实现。)
问题
在发布之前,请填写问题模板。
作者
- 基础项目由gotnovik创建。
- Swift版本由GTMYang实现。
- 本项目受到CONNOR ATHERTON
ANActivityIndicator由以下人员实现
Arda Oğul Üçpınar。
