This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathINTUAnimationEngine.h
152 lines (131 loc) · 8.94 KB
/
INTUAnimationEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// INTUAnimationEngine.h
// https://github.com/intuit/AnimationEngine
//
// Copyright (c) 2014-2015 Intuit Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import "INTUAnimationEngineDefines.h"
#import "INTUEasingFunctions.h"
#import "INTUInterpolationFunctions.h"
__INTU_ASSUME_NONNULL_BEGIN
/**
A unique ID that corresponds to one animation.
*/
typedef NSInteger INTUAnimationID;
/**
Animation options that can be used with INTUAnimationEngine.
*/
typedef NS_OPTIONS(NSUInteger, INTUAnimationOptions) {
/** Default, no options. */
INTUAnimationOptionNone = 0,
/** Repeat animation indefinitely until canceled. Note: completion block will only be executed if animation is canceled. */
INTUAnimationOptionRepeat = 1 << 0,
/** If repeat, run animation forwards and backwards. */
INTUAnimationOptionAutoreverse = 1 << 1
};
/**
A friendly interface to drive custom animations using a CADisplayLink, inspired by the UIView block-based animation API. Enables interactive
animations (normally driven by user input, such as a pan or pinch gesture) to run automatically over a given duration.
*/
@interface INTUAnimationEngine : NSObject
/**
Executes a block of animations multiple times over a given duration, passing in a percentage value each time to be used to drive the animation.
The percentage value is simply the percentage complete the animation is, based on its duration. It will increase from 0.0 to 1.0 linearly with
time.
@param duration The duration of the animation in seconds.
@param delay The delay before starting the animation in seconds.
@param animations A block which is executed at each display frame with the current animation percentage complete. This percentage value should
be used to update views so that they can be rendered onscreen in the next frame with this updated state.
@param completion A block which is executed at the completion of the animation, with the finished parameter indicating whether the animation
completed without interruption (or was canceled).
@return A unique INTUAnimationID for this animation. Can be used to cancel the animation at a later point in time.
*/
+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
animations:(__INTU_NULLABLE void (^)(CGFloat percentage))animations
completion:(__INTU_NULLABLE void (^)(BOOL finished))completion;
/**
Executes a block of animations multiple times over a given duration, passing in a progress value each time to be used to drive the animation.
The progress value is a function of the animation's percentage complete (based on its duration) and the easing function provided.
@param duration The duration of the animation in seconds.
@param delay The delay before starting the animation in seconds.
@param easingFunction An easing function used to apply a curve to the animation (affects the progress value passed into the animations block).
@param animations A block which is executed at each display frame with the current animation progress. This progress value should be used to
update views so that they can be rendered onscreen in the next frame with this updated state.
@param completion A block which is executed at the completion of the animation, with the finished parameter indicating whether the animation
completed without interruption (or was canceled).
@return A unique INTUAnimationID for this animation. Can be used to cancel the animation at a later point in time.
*/
+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
easing:(__INTU_NULLABLE INTUEasingFunction)easingFunction
animations:(__INTU_NULLABLE void (^)(CGFloat progress))animations
completion:(__INTU_NULLABLE void (^)(BOOL finished))completion;
/**
Executes a block of animations multiple times over a given duration, passing in a progress value each time to be used to drive the animation.
The progress value is a function of the animation's percentage complete (based on its duration) and the easing function provided.
@param duration The duration of the animation in seconds.
@param delay The delay before starting the animation in seconds.
@param easingFunction An easing function used to apply a curve to the animation (affects the progress value passed into the animations block).
@param options A mask of options to apply to the animation. See the constants in INTUAnimationOptions.
@param animations A block which is executed at each display frame with the current animation progress. This progress value should be used to
update views so that they can be rendered onscreen in the next frame with this updated state.
@param completion A block which is executed at the completion of the animation, with the finished parameter indicating whether the animation
completed without interruption (or was canceled).
@return A unique INTUAnimationID for this animation. Can be used to cancel the animation at a later point in time.
*/
+ (INTUAnimationID)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
easing:(__INTU_NULLABLE INTUEasingFunction)easingFunction
options:(INTUAnimationOptions)options
animations:(__INTU_NULLABLE void (^)(CGFloat progress))animations
completion:(__INTU_NULLABLE void (^)(BOOL finished))completion;
/**
Executes a block of animations multiple times over a duration that is determined by the physics of a spring, passing in a progress value each
time to be used to drive the animation. The progress value is determined by simulating a spring-mass sytem with the given properties (damping,
stiffness, mass).
@param damping The amount of friction. Must be greater than or equal to zero. If exactly zero, the harmonic motion will continue
indefinitely. Typical range: 1.0 to 30.0
@param stiffness The stiffness of the spring. Must be greater than zero. Typical range: 1.0 to 500.0
@param mass The amount of mass being moved by the spring. Must be greater than zero. Typical range: 0.1 to 10.0
@param delay The delay before starting the animation in seconds.
@param animations A block which is executed at each display frame with the current animation progress. This progress value should be used to
update views so that they can be rendered onscreen in the next frame with this updated state.
@param completion A block which is executed at the completion of the animation, with the finished parameter indicating whether the animation
completed without interruption (or was canceled).
@return A unique INTUAnimationID for this animation. Can be used to cancel the animation at a later point in time.
*/
+ (INTUAnimationID)animateWithDamping:(CGFloat)damping
stiffness:(CGFloat)stiffness
mass:(CGFloat)mass
delay:(NSTimeInterval)delay
animations:(__INTU_NULLABLE void (^)(CGFloat progress))animations
completion:(__INTU_NULLABLE void (^)(BOOL finished))completion;
/**
Cancels the currently active animation with the given animation ID.
The completion block for the animation will be executed, with the finished parameter equal to NO.
If there is no active animation for the given ID, this method will do nothing.
*/
+ (void)cancelAnimationWithID:(INTUAnimationID)animationID;
@end
__INTU_ASSUME_NONNULL_END