Skip to content

Commit 7e3417d

Browse files
committed
1.3.0 update
- Refactored the "finalState" convenience initializer for the Motion class to now take an Array of PropertyStates objects. This allows you to provide both starting and ending representational value objects for easy animation properties creation. Most of the ValueAssistant objects had significant updates to support this. - A new "buildPropertyData(fromObject: AnyObject, propertyStates: [PropertyStates])" public method has been added to the Motion class, which creates and returns an array of PropertyData objects. This method is used in conjunction with the above convenience initializer, but can be called ad hoc to generate PropertyData objects from a set of state objects you pass in. - Bugfix: ValueAssistants now won't exclude properties from being created when the ending value is the same as the object's original value, but the specified starting value is different. - Minor updates for Swift 4 compatibility. The Examples and Tests projects now target Swift 4. - Updated tests, and additional test coverage for ValueAssistant classes.
1 parent 49745e4 commit 7e3417d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1361
-586
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#### 1.3.0
2+
- Refactored the "finalState" convenience initializer for the Motion class to now take an Array of PropertyStates objects. This allows you to provide both starting and ending representational value objects for easy animation properties creation. Most of the ValueAssistant objects had significant updates to support this.
3+
- A new "buildPropertyData(fromObject: AnyObject, propertyStates: [PropertyStates])" public method has been added to the Motion class, which creates and returns an array of PropertyData objects. This method is used in conjunction with the above convenience initializer, but can be called ad hoc to generate PropertyData objects from a set of state objects you pass in.
4+
- Bugfix: ValueAssistants now won't exclude properties from being created when the ending value is the same as the object's original value, but the specified starting value is different.
5+
- Minor updates for Swift 4 compatibility. The Examples and Tests projects now target Swift 4.
6+
- Updated tests, and additional test coverage for ValueAssistant classes.
7+
18
#### 1.2.0
29
Support for Swift 4.0.
310

Classes/CATempo.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/19/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingBack.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingBounce.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingCircular.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingCubic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingElastic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingExpo.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingLinear.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/19/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingQuadratic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/30/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingQuartic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingQuintic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/EasingTypes/EasingSine.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/3/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/Motion.swift

+70-46
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/19/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal
@@ -524,7 +524,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
524524
*/
525525
public convenience init(target targetObject: NSObject, properties: [PropertyData], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {
526526

527-
self.init(target: targetObject, properties: properties, finalStates: nil, duration: duration, easing: easing, options: options)
527+
self.init(target: targetObject, properties: properties, statesForProperties: nil, duration: duration, easing: easing, options: options)
528528

529529
}
530530

@@ -539,26 +539,26 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
539539
*/
540540
public convenience init(target targetObject: NSObject, duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {
541541

542-
self.init(target: targetObject, properties: [], finalStates: nil, duration: duration, easing: easing, options: options)
542+
self.init(target: targetObject, properties: [], statesForProperties: nil, duration: duration, easing: easing, options: options)
543543
}
544544

545545
/**
546-
* Initializer.
546+
* Initializer. Using this convenience method, you can pass in objects of the value type you're modifying without having to manually create `PropertyData` objects for each object property you wish to modify. For instance, if you're modifying a CGRect object, you can provide CGRect objects that represent its starting and ending states and it will handle the setup for all the properties of the CGRect that have changed between the two states.
547547
*
548548
* - parameters:
549549
* - target: The target object whose properties should be modified.
550-
* - finalState: A Dictionary of template objects, with keys representing property keypaths (relative to the target object), and values that represent their final states. These final states must be of the same object type as the property located at the keypath.
550+
* - statesForProperties: An Array of `PropertyStates` objects which represent property keypaths (relative to the target object), and values that represent their starting and ending states. By using `PropertyStates` objects, you can pass in objects of the value type you're modifying without having to manually create `PropertyData` objects for each object property you wish to modify. Please see the `PropertyStates` documentation for usage information.
551551
* - duration: The length of the motion, in seconds.
552552
* - easing: An optional `EasingUpdateClosure` easing equation to use when moving the values of the given properties. `EasingLinear.easeNone()` is the default equation if none is provided.
553553
* - options: An optional set of `MotionsOptions`.
554554
*/
555-
public convenience init(target targetObject: NSObject, finalState templateObjects: [String:Any], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {
555+
public convenience init(target targetObject: NSObject, statesForProperties templateObjects: [PropertyStates], duration: TimeInterval, easing: EasingUpdateClosure?=EasingLinear.easeNone(), options: MotionOptions?=MotionOptions.None) {
556556

557-
self.init(target: targetObject, properties: nil, finalStates: templateObjects, duration: duration, easing: easing, options: options)
557+
self.init(target: targetObject, properties: nil, statesForProperties: templateObjects, duration: duration, easing: easing, options: options)
558558
}
559559

560560

561-
private init(target targetObject: NSObject, properties props: [PropertyData]?, finalStates: [String:Any]?, duration: TimeInterval, easing: EasingUpdateClosure?, options: MotionOptions?) {
561+
private init(target targetObject: NSObject, properties props: [PropertyData]?, statesForProperties: [PropertyStates]?, duration: TimeInterval, easing: EasingUpdateClosure?, options: MotionOptions?) {
562562

563563
var properties = props ?? []
564564

@@ -587,43 +587,8 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
587587

588588
_tempo?.delegate = self
589589

590-
if let final_object_states = finalStates {
591-
for (path, final_state) in final_object_states {
592-
var tobj: AnyObject = targetObject
593-
if (path != "" && valueAssistant.acceptsKeypath(targetObject)) {
594-
if let tvalue = targetObject.value(forKeyPath: path) as AnyObject? {
595-
tobj = tvalue
596-
}
597-
}
598-
599-
if let val = CGStructAssistant.valueForCGStruct(final_state) {
600-
do {
601-
let generated = try valueAssistant.generateProperties(fromObject: val, keyPath: path, targetObject: tobj)
602-
properties.append(contentsOf: generated)
603-
604-
} catch ValueAssistantError.typeRequirement(let valueType) {
605-
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)
606-
607-
} catch {
608-
// any other errors
609-
}
610-
611-
} else {
612-
do {
613-
let generated = try valueAssistant.generateProperties(fromObject: (final_state as AnyObject), keyPath: path, targetObject: tobj)
614-
properties.append(contentsOf: generated)
615-
616-
} catch ValueAssistantError.typeRequirement(let valueType) {
617-
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)
618-
619-
} catch {
620-
// any other errors
621-
}
622-
623-
}
624-
625-
}
626-
590+
if let unwrapped_states = statesForProperties {
591+
properties = buildPropertyData(forObject: targetObject, propertyStates: unwrapped_states)
627592
}
628593

629594
for property in properties {
@@ -710,7 +675,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
710675
*
711676
* - remark: When this method is used there is no need to specify `.Reverse` in the `options` parameter of the init method.
712677
*
713-
* - parameter easing: The easing equation to be used while reversing. When no equation is provided, the normal `easing` closure will be used in both movement directions.
678+
* - parameter withEasing: The easing equation to be used while reversing. When no equation is provided, the normal `easing` closure will be used in both movement directions.
714679
* - returns: A reference to this Motion instance, for the purpose of chaining multiple calls to this method.
715680
* - seealso: reversing, reverseEasing
716681
*/
@@ -723,6 +688,64 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
723688
}
724689

725690

691+
/**
692+
* Builds `PropertyData` objects for the supplied PropertyStates objects.
693+
*
694+
* - parameter forObject: The object to be modified, and the base object for the paths of the `PropertyStates` objects.
695+
* - parameter propertyStates: An Array of `PropertyStates` objects that define how the `PropertyData` objects are constructed.
696+
* - remark: This method is used internally by the initializer when the `statesForProperties` convenience method is used, but you can also call it directly to build an array of `PropertyData` objects.
697+
* - returns: An Array of `PropertyData` objects.
698+
*/
699+
public func buildPropertyData(forObject targetObject: AnyObject, propertyStates: [PropertyStates]) -> [PropertyData] {
700+
var data: [PropertyData] = []
701+
702+
for var property_states in propertyStates {
703+
var tobj: AnyObject = targetObject
704+
if (property_states.path != "" && valueAssistant.acceptsKeypath(targetObject)) {
705+
if let tvalue = targetObject.value(forKeyPath: property_states.path) as AnyObject? {
706+
tobj = tvalue
707+
}
708+
}
709+
710+
if let end_val = CGStructAssistant.valueForCGStruct(property_states.end) {
711+
do {
712+
// the `generateProperties` method expects AnyObject for the states, so convert them to NSValue if we have a CGStruct
713+
property_states.end = end_val
714+
if let unwrapped_start = property_states.start, let start_val = CGStructAssistant.valueForCGStruct(unwrapped_start) {
715+
property_states.start = start_val
716+
}
717+
718+
let generated = try valueAssistant.generateProperties(targetObject: tobj, propertyStates: property_states)
719+
data.append(contentsOf: generated)
720+
721+
} catch ValueAssistantError.typeRequirement(let valueType) {
722+
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)
723+
724+
} catch {
725+
// any other errors
726+
}
727+
728+
} else {
729+
do {
730+
let generated = try valueAssistant.generateProperties(targetObject: tobj, propertyStates: property_states)
731+
data.append(contentsOf: generated)
732+
733+
} catch ValueAssistantError.typeRequirement(let valueType) {
734+
ValueAssistantError.typeRequirement(valueType).printError(fromFunction: #function)
735+
736+
} catch {
737+
// any other errors
738+
}
739+
740+
}
741+
742+
}
743+
744+
return data
745+
}
746+
747+
748+
726749
// MARK: - Private methods
727750

728751
/**
@@ -935,6 +958,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
935958
private func updatePropertyValue(forProperty property: inout PropertyData) {
936959

937960
let new_value = (additive) ? property.delta : property.current
961+
938962
if (property.targetObject == nil) {
939963

940964
if let new_prop = valueAssistant.calculateValue(forProperty: property, newValue: new_value) {

Classes/MotionGroup.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/6/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/MotionMachine.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/19/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal
@@ -237,6 +237,8 @@ public protocol MotionUpdateDelegate: class {
237237
/// This protocol defines methods and properties that must be adopted for any value assistant.
238238
public protocol ValueAssistant {
239239

240+
init()
241+
240242
/**
241243
* This method returns an array of PropertyData instances based on the values of the provided object.
242244
*
@@ -247,7 +249,7 @@ public protocol ValueAssistant {
247249
*
248250
* - returns: An array of PropertyData instances representing the values of the provided object.
249251
*/
250-
func generateProperties(fromObject object: AnyObject, keyPath path: String, targetObject target: AnyObject) throws -> [PropertyData]
252+
func generateProperties(targetObject target: AnyObject, propertyStates: PropertyStates) throws -> [PropertyData]
251253

252254
/**
253255
* This method replaces an element of an AnyObject subclass by assigning new values.

Classes/MotionSequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/11/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/MotionSupport.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 4/20/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/PhysicsMotion.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/16/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

Classes/PhysicsSystem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MotionMachine
44
//
55
// Created by Brett Walker on 5/16/16.
6-
// Copyright © 2016 Poet & Mountain, LLC. All rights reserved.
6+
// Copyright © 2016-2018 Poet & Mountain, LLC. All rights reserved.
77
//
88
// Permission is hereby granted, free of charge, to any person obtaining a copy
99
// of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)