MotionSupport
@MainActor
public struct MotionSupport
This struct provides utility methods for Motion classes.
-
Registers an
Additivemotion. Any custom classes that conform to theAdditiveprotocol should register their motion object.Declaration
Swift
@MainActor public static func register(additiveMotion motion: any Additive) -> UIntParameters
additiveMotionThe
Additiveobject to register.Return Value
An operation ID that should be assigned to the
Additiveobject’soperationIDproperty. -
Removes an
Additivemotion from the registered list. Any custom classes that conform to theAdditiveprotocol should call this method when it has completed its motion.Declaration
Swift
@MainActor public static func unregister(additiveMotion motion: any Additive)Parameters
additiveMotionThe
Additiveobject to remove. -
Returns the ending value of the most recently started
Additivemotion operation for the specified object and keyPath. In order to participate in additive motion with otherAdditiveobjects, custom objects should use this method to set a starting value.Example Usage
if let lastTargetValue = MotionSupport.targetValue(forObject: targetObject, targetProperty: property, requestingID: self.operationID) { properties[index].start = lastTargetValue }Declaration
Swift
@MainActor public static func targetValue<TargetType>(forObject object: TargetType, targetProperty: PropertyData<TargetType>, requestingID: UInt) -> Double? where TargetType : AnyObjectParameters
forObjectThe object whose property value should be queried.
keyPathThe keypath of the target property, relative to the object.
Return Value
The ending value. Returns
nilif noAdditiveobject is targeting this property.
-
Builds and returns a
PropertyDataobject using the supplied values.A
PropertyDataobject will be created if the values you supply pass one of the following tests: 1) there’s a specified start value and that value is different than either the original value or the ending value, or 2) there’s just an original value and that value is different than the ending value, or 3) there’s no start value passed in, which will return aPropertyDataobject with only an end value. In cases 1 and 2, aPropertyDataobject with both start and end values will be returned. In the third case, aPropertyDataobject that only has an ending value will be returned. If all those tests fail, no object will be returned.Declaration
Swift
@MainActor public static func buildPropertyData<TargetType, PropertyType>(keyPath: KeyPath<TargetType, PropertyType>, originalValue: PropertyType? = nil, startValue: PropertyType?, endValue: PropertyType, isAdditive: Bool = false) -> PropertyData<TargetType>? where PropertyType : BinaryFloatingPointParameters
keyPathA base
KeyPathto be used for thePropertyData‘skeyPathproperty.originalValueAn optional value representing the current value of the target object property.
startValueAn optional value to be supplied to the
PropertyData‘sstartproperty.endValueA value to be supplied to the
PropertyData‘sendproperty.isAdditiveDenotes whether this
PropertyDatawill be used with an additive Motion. Iftrue, optimizations that prevent thePropertyDatafrom being built will not occur as it would result in incorrect additive calculations.Return Value
An optional
PropertyDataobject using the supplied values. -
Builds and returns a
PropertyDataobject using the supplied values.A
PropertyDataobject will be created if the values you supply pass one of the following tests: 1) there’s a specified start value and that value is different than either the original value or the ending value, or 2) there’s just an original value and that value is different than the ending value, or 3) there’s no start value passed in, which will return aPropertyDataobject with only an end value. In cases 1 and 2, aPropertyDataobject with both start and end values will be returned. In the third case, aPropertyDataobject that only has an ending value will be returned. If all those tests fail, no object will be returned.Declaration
Swift
@MainActor public static func buildPropertyData<TargetType, PropertyType, ParentType>(keyPath: KeyPath<TargetType, PropertyType>, parentPath: KeyPath<TargetType, ParentType>? = nil, originalValue: PropertyType? = nil, startValue: PropertyType?, endValue: PropertyType, isAdditive: Bool = false) -> PropertyData<TargetType>? where PropertyType : BinaryFloatingPointParameters
keyPathA base
KeyPathto be used for thePropertyData‘skeyPathproperty.parentPathA
KeyPathreferencing the parent object to the value being updated.originalValueAn optional value representing the current value of the target object property.
startValueAn optional value to be supplied to the
PropertyData‘sstartproperty.endValueA value to be supplied to the
PropertyData‘sendproperty.isAdditiveDenotes whether this
PropertyDatawill be used with an additive Motion. Iftrue, optimizations that prevent thePropertyDatafrom being built will not occur as it would result in incorrect additive calculations.Return Value
An optional
PropertyDataobject using the supplied values.
View on GitHub