Spruce
public struct Spruce
Access to all of the Spruce library animations. Use this to call functions such as .animate
or .prepare
-
Use this method to setup all of your views before the animation occurs. This could include hiding, fading, translating them, etc…
Declaration
Swift
public func prepare(withRecursiveDepth recursiveDepth: Int = 0, changeFunction: ChangeFunction)
Parameters
recursiveDepth
an int describing how deep into the view hiearchy the subview search should go
changeFunction
a function that should be applied to each of the subviews of
this
-
Run a spruce style animation on this view. This is a customized method that allows you to take more control over how the animation progresses.
Declaration
Swift
public func animate(withSortFunction sortFunction: SortFunction, prepare: PrepareHandler? = nil, animation: Animation, exclude: [UIView]? = nil, recursiveDepth: Int = 0, completion: CompletionHandler? = nil)
Parameters
sortFunction
the
SortFunction
used to determine the animation offsets for each subviewprepare
a closure that will be called with each subview of
this
parent viewanimation
a
Animation
that will be used to animate each subviewexclude
an array of views that the animation should skip over
recursiveDepth
an int describing how deep into the view hiearchy the subview search should go, defaults to 0
completion
a closure that is called upon the final animation completing. A
Bool
is passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalse
will be passed into the completion closure. However, if the final animation is allowed to proceed thentrue
will be the value passed into the completion closure.
-
Run a spruce style animation on this view. This method is the most basic form of a spruce animation and allows you to setup your view with stock spruce animations. Feel free to chain together animations that would work nicely together.
Note
Possible animations include- Fading
- Scaling
- Translating
- Rotating
Note
Default animation type isStandardAnimation
and SortFunction isLinearSortFunction(direction: .topToBottom, interObjectDelay: 0.05)
See
StockAnimation
for more detailsDeclaration
Swift
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, completion: CompletionHandler? = nil )
Parameters
animations
an array of stock animations
duration
duration of each individual animation
completion
a closure that is called upon the final animation completing. A
Bool
is passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalse
will be passed into the completion closure. However, if the final animation is allowed to proceed thentrue
will be the value passed into the completion closure. -
Run a spruce style animation on this view. This allows you to setup your view with stock spruce animations. Feel free to chain together animations that would work nicely together.
Note
Possible animations include- Fading
- Scaling
- Translating
- Rotating
Note
Default animation type isStandardAnimation
See
StockAnimation
for more detailsDeclaration
Swift
public func animate(_ animations: [StockAnimation], sortFunction: SortFunction, duration: TimeInterval = 0.3, completion: CompletionHandler? = nil )
Parameters
animations
an array of stock animations
duration
duration of each individual animation
sortFunction
the
sortFunction
to be used when setting the offsets for each subviews animationcompletion
a closure that is called upon the final animation completing. A
Bool
is passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalse
will be passed into the completion closure. However, if the final animation is allowed to proceed thentrue
will be the value passed into the completion closure. -
Run a spruce style animation on this view. This method allows you to setup your view with stock spruce animations. Feel free to chain together animations that would work nicely together.
Note
Default SortFunction isLinearSortFunction(direction: .topToBottom, interObjectDelay: 0.05)
Declaration
Swift
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, completion: CompletionHandler? = nil)
Parameters
animations
an array of stock animations
duration
duration of each individual animation
animationType
style of animation that each view should follow. Don’t worry about setting the
changeFunction
. We will set that using the stock animations that you provide. If you have a value there it will be overwritten. (ex: SpringAnimation)completion
a closure that is called upon the final animation completing. A
Bool
is passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalse
will be passed into the completion closure. However, if the final animation is allowed to proceed thentrue
will be the value passed into the completion closure. -
Run a spruce style animation on this view. This method allows you to setup your view with stock spruce animations. Feel free to chain together animations that would work nicely together.
Declaration
Swift
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, sortFunction: SortFunction, prepare: Bool = true, completion: CompletionHandler? = nil)
Parameters
animations
an array of stock animations
duration
duration of each individual animation
animationType
style of animation that each view should follow. Don’t worry about setting the
changeFunction
. We will set that using the stock animations that you provide. If you have a value there it will be overwritten. (ex: SpringAnimation)sortFunction
the
sortFunction
to be used when setting the offsets for each subviews animationprepare
a
bool
as to whether we should runprepare
on your view for you. If set totrue
, then we will runprepare
right before the animation using the stock animations that you provided. Iffalse
, thenprepare
will not run. (default istrue
)completion
a closure that is called upon the final animation completing. A
Bool
is passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalse
will be passed into the completion closure. However, if the final animation is allowed to proceed thentrue
will be the value passed into the completion closure. -
Use this method to setup all of your views before the animation occurs. This could include hiding, fading, translating them, etc… Given the array of stock animations, the change functions required to prepare those animations will automatically be run for you. No need to specify your own custom change function here. - Note: If you run this after the views are visible, then this would cause a slight stutter of the viewport. This could cause UX issues since the views would flash on the screen.
Declaration
Swift
public func prepare(with animations: [StockAnimation], recursiveDepth: Int = 0)
Parameters
animations
an array of stock animations
recursiveDepth
an int describing how deep into the view hiearchy the subview search should go
-
Quick method to hide all of the subviews of a view. Use this if you want to make sure that none of the views that will be animated will be shown on screen before you transition them.
Declaration
Swift
public func hideAllSubviews(recursiveDepth: Int = 0)
Parameters
recursiveDepth
an int describing how deep into the view hiearchy the subview search should go
-
The receiver’s immediate subviews given the recursive depth. If a subview contains other subviews, they will be listed in the array following their parent view. Consider the following example:
// A: [B, C] // B: [D, E] // C: [] // D: [] // E: [] let result = A.spruce.subviews(withRecursiveDepth: 1) // result: [A, B, D, E, C]
Note
This method will return an array ofView
. These are used so that when we adjust for coordinate space differences, it does not affect the way your screen renders. AView
is a simple struct withview: UIView
andreferencePoint: CGPoint
variables.Precondition
recursiveDepth
is an Int >= 0 (0…Int.max).Declaration
Swift
public func subviews(withRecursiveDepth recursiveDepth: Int) -> [View]
Parameters
recursiveDepth
an int for how deep into the view hierarchy the subview search should go
Return Value
an array of all the subviews in the receiver view. Depending on the
recursiveDepth
this could contain the subviews of subviews also.