You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
7.3 KiB

5 years ago
  1. NVActivityIndicatorView
  2. =======================
  3. [![Build Status](https://travis-ci.org/ninjaprox/NVActivityIndicatorView.svg?branch=master)](https://travis-ci.org/ninjaprox/NVActivityIndicatorView)
  4. [![Cocoapods Compatible](https://img.shields.io/cocoapods/v/NVActivityIndicatorView.svg)](https://img.shields.io/cocoapods/v/NVActivityIndicatorView.svg)
  5. [![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
  6. [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
  7. ## Introduction
  8. `NVActivityIndicatorView` is a collection of awesome loading animations.
  9. This is original a fork from [DGActivityIndicatorView](https://github.com/gontovnik/DGActivityIndicatorView), inspired by [Loaders.css](https://github.com/ConnorAtherton/loaders.css), written in Swift with full implementation of animations, plus more.
  10. You can also find Objective-C version of this [here](https://github.com/ninjaprox/DGActivityIndicatorView).
  11. ## Demo
  12. ![alt tag](https://raw.githubusercontent.com/ninjaprox/NVActivityIndicatorView/master/Demo.gif)
  13. For first-hand experience, just open the project and run it.
  14. ## Animation types
  15. | Type | Type | Type | Type |
  16. |---|---|---|---|
  17. |1. ballPulse | 2. ballGridPulse | 3. ballClipRotate | 4. squareSpin|
  18. |5. ballClipRotatePulse | 6. ballClipRotateMultiple | 7. ballPulseRise | 8. ballRotate|
  19. |9. cubeTransition | 10. ballZigZag | 11. ballZigZagDeflect | 12. ballTrianglePath|
  20. |13. ballScale | 14. lineScale | 15. lineScaleParty | 16. ballScaleMultiple|
  21. |17. ballPulseSync | 18. ballBeat | 19. lineScalePulseOut | 20. lineScalePulseOutRapid|
  22. |21. ballScaleRipple | 22. ballScaleRippleMultiple | 23. ballSpinFadeLoader | 24. lineSpinFadeLoader|
  23. |25. triangleSkewSpin | 26. pacman | 27. ballGridBeat | 28. semiCircleSpin|
  24. |29. ballRotateChase | 30. orbit | 31. audioEqualizer | 32. circleStrokeSpin|
  25. ## Installation
  26. ### Cocoapods
  27. Install Cocoapods if need be.
  28. ```bash
  29. $ gem install cocoapods
  30. ```
  31. Add `NVActivityIndicatorView` in your `Podfile`.
  32. ```ruby
  33. use_frameworks!
  34. pod 'NVActivityIndicatorView'
  35. ```
  36. Then, run the following command.
  37. ```bash
  38. $ pod install
  39. ```
  40. ### Carthage
  41. Install Carthage if need be.
  42. ```bash
  43. $ brew update
  44. $ brew install carthage
  45. ```
  46. Add `NVActivityIndicatorView` in your `Cartfile`.
  47. ```ruby
  48. github "ninjaprox/NVActivityIndicatorView"
  49. ```
  50. Run `carthage` to build the framework and drag the built `NVActivityIndicatorView.framework` into your Xcode project.
  51. _**Note:** You might encounter compile issue, if so please use `carthage` branch instead. Check issue [#101](https://github.com/ninjaprox/NVActivityIndicatorView/issues/101) for more information._
  52. ### Manual
  53. Copy `NVActivityIndicatorView` folder to your project. That's it.
  54. _**Note:** Make sure that all files in `NVActivityIndicatorView` included in Compile Sources in Build Phases._
  55. _**Note:** If you encounter issues while uploading the app to iTunes Connect, remove the `Info.plist` file in `NVActivityIndicatorView`. Check issue [#129](https://github.com/ninjaprox/NVActivityIndicatorView/issues/129) for more information._
  56. ## Migration
  57. ### Version 4.0.0
  58. This version requires Xcode 9.0 and Swift 4.
  59. ### Version 3.7.0
  60. This version splits `NVActivityIndicatorView` pod to 2 subpods `NVActivityIndicatorView/Presenter` and `NVActivityIndicatorView/AppExtension`. There is no need to change `pod NVActivityIndicatorView` to `pod NVActivityIndicatorView/Presenter` since it will be installed by default if you use the main pod name.
  61. However, if you want to use `NVActivityIndicatorView` in app extension, use `pod NVActivityIndicatorView/AppExtension` instead.
  62. _**Note:** Related issue [#119](https://github.com/ninjaprox/NVActivityIndicatorView/issues/119)._
  63. ### Version 3.6.0
  64. This version requires Xcode 8.3 and Swift 3.1.
  65. ### Version 3.0
  66. This version requires Xcode 8.0 and Swift 3.
  67. - `NVActivityIndicatorView.startAnimation()` and `NVActivityIndicatorView.stopAnimation()` are deleted. Use `NVActivityIndicatorView.startAnimating()` and `NVActivityIndicatorView.stopAnimating()` instead.
  68. - `UIViewController.startActivityAnimating()` and `UIViewController.stopActivityAnimating()` are deleted. Use `UIViewController.startAnimating()` and `UIViewController.stopAnimating()` instead.
  69. ### Version 2.0
  70. This version continues to spport Xcode 7.0 and Swift 2.2 and earlier.
  71. For Swift 2.3 support, use `swift2.3` branch instead.
  72. ```ruby
  73. pod 'NVActivityIndicatorView', :git => 'https://github.com/ninjaprox/NVActivityIndicatorView.git', :branch => 'swift2.3'
  74. ```
  75. ## Usage
  76. Firstly, import `NVActivityIndicatorView`.
  77. ```swift
  78. import NVActivityIndicatorView
  79. ```
  80. ### Initialization
  81. Then, there are two ways you can create NVActivityIndicatorView:
  82. - By storyboard, changing class of any `UIView` to `NVActivityIndicatorView`.
  83. _**Note:** Set Module to `NVActivityIndicatorView`._
  84. - By code, using initializer. All parameters other than `frame` are optional and `NVActivityIndicatorView.DEFAULT_*` are used as default values.
  85. ```swift
  86. NVActivityIndicatorView(frame: frame, type: type, color: color, padding: padding)
  87. ```
  88. ### Control
  89. Start animating.
  90. ```swift
  91. activityIndicatorView.startAnimating()
  92. ```
  93. Stop animating.
  94. ```swift
  95. activityIndicatorView.stopAnimating()
  96. ```
  97. Determine if it is animating.
  98. ```swift
  99. animating = activityIndicatorView.isAnimating
  100. ```
  101. ### Change properties
  102. In storyboard, you can change all properties in Attributes inspector tab of Utilities panel.
  103. _**Note:** Use one of values (case-insensitive) in [Animation types](#animation-types) for `Type Name`._
  104. All properties are public so you can change them after initializing.
  105. _**Note:** All changes must be made before calling `startAnimating()`._
  106. ### UI blocker
  107. By conforming `NVActivityIndicatorViewable` protocol, you can use `NVActivityIndicatorView` as UI blocker for `UIViewController`.
  108. ```swift
  109. class ViewController: UIViewController, NVActivityIndicatorViewable { }
  110. ```
  111. Start animating.
  112. ```swift
  113. startAnimating(size, message) // plus other parameters as in initializer.
  114. ```
  115. Stop animating.
  116. ```swift
  117. stopAnimating()
  118. ```
  119. Check if it is animating.
  120. ```swift
  121. animating = isAnimating
  122. ```
  123. Or you can use `NVActivityIndicatorPresenter` to display UI blocker anywhere.
  124. Start animating.
  125. ```swift
  126. let activityData = ActivityData()
  127. NVActivityIndicatorPresenter.sharedInstance.startAnimating(activityData)
  128. ```
  129. _**Note:** Check [documentation](http://cocoadocs.org/docsets/NVActivityIndicatorView) for detail of `ActivityData`._
  130. Stop animating.
  131. ```swift
  132. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  133. ```
  134. Change message.
  135. ```swift
  136. NVActivityIndicatorPresenter.sharedInstance.setMessage("Done")
  137. ```
  138. Check if it is animating.
  139. ```swift
  140. animating = NVActivityIndicatorPresenter.sharedInstance.isAnimating
  141. ```
  142. #### Fade in/out animation
  143. You have control over showing and hiding UI blocker animation.
  144. ```swift
  145. startAnimating(fadeInAnimation: fadeInAnimation)
  146. stopAnimating(fadeOutAnimation)
  147. ```
  148. Check `DEFAULT_FADE_IN_ANIMATION` and `DEFAULT_FADE_OUT_ANIMATION` for examples of how to implement animation.
  149. ## Acknowledgment
  150. Thanks [Connor Atherton](https://github.com/ConnorAtherton) for great loaders and [Danil Gontovnik](https://github.com/gontovnik) for kick-start.
  151. ## License
  152. The MIT License (MIT)
  153. Copyright (c) 2016 Vinh Nguyen [@ninjaprox](http://twitter.com/ninjaprox)