ANActivityIndicatorView 1.2.0

ANActivityIndicatorView 1.2.0

Avornaanelad 维护。



ANActivityIndicatorView

Xcode 9.0+ iOS 10.0+ Swift 4.0+ Version carthage

ANActivityIndicatorView 是一个预构建的指示器动画库,基于 gontovnik 的 DGActivityIndicatorViewGTMYang 的 GTMActivityIndicatorView,并受到 loaders.css(CONNOR ATHERTON)的启发。

我为什么将 ANActivityIndicatorView 放在一个单独的仓库中?

首先,我并不是想获得所有这个项目的荣誉。我并没有为 gotnovik 的作品和 GTMYang 的作品做出什么值得称道的事情。

那么,为什么我要将 ANActivityIndicatorView 放在一个单独的仓库中呢?

看起来 gotnovik 没有更新他的仓库,而 GTMYang 的仓库集中关注于与我的使用方法略有不同的用法。

一般差异

与 DGActivityIndicatorView 之间的区别

  • 使用 Swift 实现

在GTMActivityIndicatorView之间

  • 使用Swift 4实现
  • 提供了预构建的指示器动画,使用GTMActivityIndicatorView时,您需要手动将动画添加到您的项目中。

新增功能

  • 自定义动画结构(类似于NSNotification.Name的结构体)。
  • 自定义加载信息边距。

示例

查看预构建动画类型部分,查看动画类型。

demo-gif

要求

  • XCode 9.x或更高版本
  • Swift 4.x
  • iOS 10.0或更高版本

安装

CocoaPods

pod 'ANActivityIndicator'

手动安装

  1. 下载仓库

作为框架

  1. ANActivityIndicatorSource文件夹复制到您的项目目录。
  2. [项目目录]/ANActivityIndicator/ANActivityIndicator.xcodeproj添加到您的“工作区”中。
  3. 项目设置 -> 一般中,将ANActivityIndicator.framework添加到嵌入式二进制文件链接框架和库

作为子项目

  1. ANActivityIndicatorSource文件夹复制到您的项目目录。
  2. ANActivityIndicator/ANActivityIndicator.xcodeproj添加到您的“项目”中。

作为代码

  1. ANActivityIndicatorSource文件夹复制到您的工作区/项目目录。
  2. [工作区/项目目录]/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()

预置动画类型

以下是预置动画列表。您可以在示例部分查看它们的外观。(按编号排序)

  1. .audioEqualizer
  2. .ballBeat
  3. .ballClipRotate
  4. .ballClipRotateMultiple
  5. .ballClipRotatePulse
  6. .ballGridBeat
  7. .ballGridPulse
  8. .ballPulse
  9. .ballPulseRise
  10. .ballPulseSync
  11. .ballRotate
  12. .ballRotateChase
  13. .ballScale
  14. .ballScaleMultiple
  15. .ballScaleRipple
  16. .ballScaleRippleMultiple
  17. .ballSpinFadeLoader
  18. .ballTrianglePath
  19. .ballZigZag
  20. .ballZigZagDeflect
  21. .blank
  22. .cubeTransition
  23. .lineScale
  24. .lineScaleParty
  25. .lineScalePulseOut
  26. .lineScalePulseOutRapid
  27. .lineSpinFadeLoader
  28. .orbit
  29. .pacman
  30. .semiCircleSpin
  31. .squareSpin
  32. .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。(尚未实现。)

问题

在发布之前,请填写问题模板

作者

ANActivityIndicator由以下人员实现

Arda Oğul Üçpınar。