Actions and CAAnimations

Whenever you retrieve an animation from LWKLoadingContext‘s animation accessors, a CAAnimation will be returned. Based on the type of the animation setup within the Lightwell editor either a CAAnimationGroup or a CAKeyframeAnimation will be returned.

The keyframe animations will already be setup with keypaths, values, durations, keytimes, and timining functions. Since these are native elements you have full access to futher edit or customize the animations further.

To play an animation, first retrieve it from the loading context, then attach it to a CALayer:

import HullabaluStoryKit
...
// Initialize the context
let loadingContext = LWKLoadingContext(screenName: "my awesome screen")
...
// Retrieve animation
if let animation = self.loadingContext?.animation(for: "my animation") {
    // Play animation
    view.layer.add(animation, forKey: nil)
}
...

Note that CAAnimations do not modify the underlying value (always reset to the original value), do not store target information, and do not support groups that have animations targeting multiple different layers.

LWKAction is a wrapper for CAAnimations that add support for multiple targets within the same animation, and different targets within a group. Depending on the fill mode, LWKCAAnimation will also update the underlying value to smoothly transition from the end of the animation to the final state. LWKAction also adds simple run symatics so that you only need a reference to the action to begin any animations.

import HullabaluStoryKit
...
// Initialize the context
let loadingContext = LWKLoadingContext(screenName: "my awesome screen")
...
// Retrieve animation
if let action = self.loadingContext?.action(for: "my animation") {
    // Run animation
    action.run()
}
...

By default, an LWKCAAnimation’s targets will be the views initialized from the linked layers setup in the Lightwell Editor from the LWKLoadingContext.loadViews(usingGenerator:) function. However, these can be changed at run time by editing the LWKCAAnimation.targets property.

The API is currently in beta and everything inside of these docs will be changing to improve the SDK. If there is a change you’d like to see or have any feedback, please email us at dev@lightwell.pro.

If you have any questions please get in touch with us via email or chat with us on lightwell.pro!

  • An action that organizes playback of other actions.

    Grouped actions are contained in LWKActionGroup.actions, and the group will end when all contained actions have completed running a number of times defined by LWKActionGroup.repeatCount.

    Calling LWKAction.stop() on an LWKActionGroup with stop any running child actions.

    Note that actions can only be in one group at a time, so adding actions to a group will remove it from any group it was previously in.

    Groups can be nested, and since repeats occur after the child actions complete, a child action’s delegate might get multiple calls to LWKActionDelegate.actionDidEnd(_:finished:) for a single run of LWKActionGroup

    See more

    Declaration

    Swift

    public class LWKActionGroup : LWKAction, LWKTimeableParent, LWKTimeableChild