Skip to content

Commit 0e45ab1

Browse files
Added DanceAnimationState
1 parent d085193 commit 0e45ab1

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

Dance.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222

2323
import UIKit
2424

25+
// MARK: - Dance Animation State
26+
27+
@available(iOS 10.0, *)
28+
public enum DanceAnimationState {
29+
case inactive // animation hasn't started yet, or no animation associated with view
30+
case active // animation exists and has started
31+
}
32+
2533
// MARK: - Dance Implementation
2634

2735
fileprivate class DanceFactory {
@@ -160,9 +168,16 @@ fileprivate class DanceFactory {
160168
}
161169

162170
/// Returns the view's UIViewPropertyAnimator current state (inactive, active, stopped).
163-
func getState(tag: Int) -> UIViewAnimatingState {
171+
func getState(tag: Int) -> DanceAnimationState {
164172
if let animator = animators[tag] {
165-
return animator.state
173+
switch animator.state {
174+
case .inactive:
175+
return DanceAnimationState.inactive
176+
case .active:
177+
return DanceAnimationState.active
178+
case .stopped:
179+
return DanceAnimationState.inactive
180+
}
166181
} else {
167182
handle(error: .noAnimation, forViewWithTag: tag)
168183
return .inactive
@@ -228,6 +243,7 @@ fileprivate class DanceFactory {
228243
// This class should only be accessed through the 'dance' variable declared in the UIView extension below.
229244
// (Dance needs to have a public modifier in order to be accessed globally through the UIView Extension.)
230245

246+
@available(iOS 10.0, *)
231247
public class Dance {
232248

233249
fileprivate var dancingView: UIView!
@@ -257,8 +273,8 @@ public class Dance {
257273
}
258274
}
259275

260-
/// GET: Returns the view's current animation state (inactive, active, stopped). Dance ensures that your animation doesn't run into any problems, so you should only ever receive .inactive or .active for any view.
261-
public var state: UIViewAnimatingState {
276+
/// GET: Returns the view's current animation state (inactive or active.) If a view has a dance animation associated with it and has not been started, then state will return .inactive. Once the animation has been started, even if it is then paused, state will return .active until the animation finishes.
277+
public var state: DanceAnimationState {
262278
get {
263279
return DanceFactory.instance.getState(tag: self.tag)
264280
}

DanceExample/ViewController.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ extension ViewController {
269269
stateLabel.text = "circle.dance.state = .active"
270270
case .inactive:
271271
stateLabel.text = "circle.dance.state = .inactive"
272-
case .stopped:
273-
stateLabel.text = "circle.dance.state = .stopped"
274272
}
275273
if circle.dance.isRunning {
276274
isRunningLabel.text = "circle.dance.isRunning = true"

0 commit comments

Comments
 (0)