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
recursiveDepthan int describing how deep into the view hiearchy the subview search should go
changeFunctiona 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
sortFunctionthe
SortFunctionused to determine the animation offsets for each subviewpreparea closure that will be called with each subview of
thisparent viewanimationa
Animationthat will be used to animate each subviewexcludean array of views that the animation should skip over
recursiveDepthan int describing how deep into the view hiearchy the subview search should go, defaults to 0
completiona closure that is called upon the final animation completing. A
Boolis passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalsewill be passed into the completion closure. However, if the final animation is allowed to proceed thentruewill 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 isStandardAnimationand SortFunction isLinearSortFunction(direction: .topToBottom, interObjectDelay: 0.05)See
StockAnimationfor more detailsDeclaration
Swift
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, completion: CompletionHandler? = nil )Parameters
animationsan array of stock animations
durationduration of each individual animation
completiona closure that is called upon the final animation completing. A
Boolis passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalsewill be passed into the completion closure. However, if the final animation is allowed to proceed thentruewill 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 isStandardAnimationSee
StockAnimationfor more detailsDeclaration
Swift
public func animate(_ animations: [StockAnimation], sortFunction: SortFunction, duration: TimeInterval = 0.3, completion: CompletionHandler? = nil )Parameters
animationsan array of stock animations
durationduration of each individual animation
sortFunctionthe
sortFunctionto be used when setting the offsets for each subviews animationcompletiona closure that is called upon the final animation completing. A
Boolis passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalsewill be passed into the completion closure. However, if the final animation is allowed to proceed thentruewill 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
animationsan array of stock animations
durationduration of each individual animation
animationTypestyle 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)completiona closure that is called upon the final animation completing. A
Boolis passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalsewill be passed into the completion closure. However, if the final animation is allowed to proceed thentruewill 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
animationsan array of stock animations
durationduration of each individual animation
animationTypestyle 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)sortFunctionthe
sortFunctionto be used when setting the offsets for each subviews animationpreparea
boolas to whether we should runprepareon your view for you. If set totrue, then we will runprepareright before the animation using the stock animations that you provided. Iffalse, thenpreparewill not run. (default istrue)completiona closure that is called upon the final animation completing. A
Boolis passed into the closure letting you know if the animation has completed. If you stop animations on the whole animating view, thenfalsewill be passed into the completion closure. However, if the final animation is allowed to proceed thentruewill 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
animationsan array of stock animations
recursiveDepthan 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
recursiveDepthan 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. AViewis a simple struct withview: UIViewandreferencePoint: CGPointvariables.Precondition
recursiveDepthis an Int >= 0 (0…Int.max).Declaration
Swift
public func subviews(withRecursiveDepth recursiveDepth: Int) -> [View]Parameters
recursiveDepthan 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
recursiveDepththis could contain the subviews of subviews also.
View on GitHub
Spruce Struct Reference