Skip to content

Commit 9fb46e0

Browse files
committed
1.3.2 Update
- fixed bugs which prevented some CGStructs from being updated when using Motion’s statesForProperties convenience initializer - added targetsNestedStruct static method to CGStructAssistant, which determines whether a specified keyPath targets a struct of a CGRect - added and improved tests - improved readability and streamlined some code
1 parent f513a42 commit 9fb46e0

19 files changed

+519
-374
lines changed

MotionMachine.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'MotionMachine'
3-
s.version = '1.3.1'
3+
s.version = '1.3.2'
44
s.swift_version = '4.0'
55
s.license = { :type => 'MIT' }
66
s.summary = 'An elegant, powerful, and modular animation library for Swift.'

Sources/EasingTypes/EasingBack.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
import Foundation
2828

2929
/**
30-
* EasingBack provides easing equations which move beyond the specified starting and ending values and snap back, as if attached to a rubber band.
30+
* EasingBack provides easing equations which move beyond the specified starting and ending values and snap back, as if attached to a rubber band. With modest overshoot values, this easing type can provide a more organic feel when animating visual elements like UIViews and UI.
3131
*
32+
* - remark: See http://easings.net for visual examples.
3233
* - warning: These equations produce easing values extending beyond the starting and ending values, which may produce unpredictable results for properties which have strict bounds limits.
3334
*/
3435
public struct EasingBack {

Sources/EasingTypes/EasingBounce.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import Foundation
2929
/**
3030
* EasingBounce provides easing equations that have successively smaller value peaks, like a bouncing ball.
3131
*
32+
* - remark: See http://easings.net for visual examples.
33+
*
3234
*/
3335
public struct EasingBounce {
3436

Sources/EasingTypes/EasingCircular.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingCircular provides circular easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingCircular {
3335

Sources/EasingTypes/EasingCubic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingCubic provides cubic easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingCubic {
3335

Sources/EasingTypes/EasingElastic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingElastic provides easing equations that behave in an elastic fashion.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingElastic {
3335

Sources/EasingTypes/EasingExpo.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingExpo provides exponential easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingExpo {
3335

Sources/EasingTypes/EasingLinear.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import Foundation
2828

2929
/**
30-
* EasingLinear provides a linear easing equation.
30+
* EasingLinear provides a linear easing equation, which increments by a constant value over time.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingLinear {
3335

Sources/EasingTypes/EasingQuadratic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingQuadratic provides quadratic easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingQuadratic {
3335

Sources/EasingTypes/EasingQuartic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingQuartic provides quartic easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingQuartic {
3335

Sources/EasingTypes/EasingQuintic.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingQuintic provides quintic easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingQuintic {
3335

Sources/EasingTypes/EasingSine.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Foundation
2828

2929
/**
3030
* EasingSine provides sine easing equations.
31+
*
32+
* - remark: See http://easings.net for visual examples.
3133
*/
3234
public struct EasingSine {
3335

Sources/Motion.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
588588
_tempo?.delegate = self
589589

590590
if let unwrapped_states = statesForProperties {
591-
properties = buildPropertyData(forObject: targetObject, propertyStates: unwrapped_states)
591+
properties = buildPropertyData(forObject: targetObject, statesForProperties: unwrapped_states)
592592
}
593593

594594
for property in properties {
@@ -692,18 +692,24 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
692692
* Builds `PropertyData` objects for the supplied PropertyStates objects.
693693
*
694694
* - 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.
695+
* - parameter statesForProperties: An Array of `PropertyStates` objects that define how the `PropertyData` objects are constructed.
696696
* - 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.
697697
* - returns: An Array of `PropertyData` objects.
698698
*/
699-
public func buildPropertyData(forObject targetObject: AnyObject, propertyStates: [PropertyStates]) -> [PropertyData] {
699+
public func buildPropertyData(forObject targetObject: AnyObject, statesForProperties: [PropertyStates]) -> [PropertyData] {
700700
var data: [PropertyData] = []
701701

702-
for var property_states in propertyStates {
702+
for var property_states in statesForProperties {
703703
var tobj: AnyObject = targetObject
704704
if (property_states.path != "" && valueAssistant.acceptsKeypath(targetObject)) {
705-
if let tvalue = targetObject.value(forKeyPath: property_states.path) as AnyObject? {
706-
tobj = tvalue
705+
706+
// here we search for a nested struct by traversing the keyPath
707+
// protects from a runtime exception since calling value(forKeyPath:) on a nested CG struct (aka CGRect) will tend to do that
708+
let is_nested_struct = CGStructAssistant.targetsNestedStruct(object: targetObject, path: property_states.path)
709+
if (!is_nested_struct) {
710+
if let tvalue = targetObject.value(forKeyPath: property_states.path) as AnyObject? {
711+
tobj = tvalue
712+
}
707713
}
708714
}
709715

@@ -885,7 +891,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
885891
* - parameter property: The `PropertyData` instance to modify.
886892
*/
887893
private func assignStartingPropertyValue(_ property: inout PropertyData) {
888-
if (property.useExistingStartValue && completedCount == 0) {
894+
if ((property.useExistingStartValue || property.start == 0) && completedCount == 0) {
889895
if let current_value = valueAssistant.retrieveCurrentObjectValue(forProperty: property) {
890896
property.start = current_value
891897
}
@@ -931,7 +937,7 @@ public class Motion: Moveable, Additive, TempoDriven, PropertyDataDelegate {
931937

932938
}
933939

934-
940+
935941

936942

937943
/**

Sources/MotionMachine.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ func ≈≈ (a: Double, b: Double) -> Bool {
587587

588588
}
589589

590+
/// Custom operators to do a "fuzzy" not-equal comparison of floating-point numbers.
591+
/// The fuzzy equal character is created using the Option-X key combination.
592+
/// see: http://stackoverflow.com/questions/4915462/how-should-i-do-floating-point-comparison
590593
infix operator !≈ : ComparisonPrecedence
591594

592595
func !≈ (a: Float, b: Float) -> Bool {

Sources/MotionSupport.swift

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ public struct MotionSupport {
186186
return selector
187187
}
188188

189+
/**
190+
* Builds and returns a `PropertyData` object 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 a `PropertyData` object with only an end value. In cases 1 and 2, a `PropertyData` object with both start and end values will be returned. In the third case, a `PropertyData` object that only has an ending value will be returned. If all those tests fail, no object will be returned.
191+
*
192+
* - parameter path: A base path to be used for the `PropertyData`'s `path` property.
193+
* - parameter originalValue: An optional value representing the current value of the target object property.
194+
* - parameter startValue: An optional value to be supplied to the `PropertyData`'s `start` property.
195+
* - parameter endValue: A value to be supplied to the `PropertyData`'s `end` property.
196+
* - returns: An optional `PropertyData` object using the supplied values.
197+
*/
198+
public static func buildPropertyData(path: String, originalValue: Double?=nil, startValue: Double?, endValue: Double) -> PropertyData? {
199+
var data: PropertyData?
200+
201+
if let unwrapped_start = startValue {
202+
if ((originalValue != nil && unwrapped_start ! originalValue!) || endValue ! unwrapped_start) {
203+
data = PropertyData(path: path, start: unwrapped_start, end: endValue)
204+
}
205+
} else if let unwrapped_org = originalValue {
206+
if (endValue ! unwrapped_org) {
207+
data = PropertyData(path: path, start: unwrapped_org, end: endValue)
208+
}
209+
} else {
210+
data = PropertyData(path: path, end: endValue)
211+
212+
}
213+
214+
return data
215+
}
216+
189217
}
190218

191219
// MARK: - Declarations
@@ -205,21 +233,21 @@ public enum ValueStructTypes {
205233
#endif
206234
case unsupported
207235

208-
static var valueTypes: [ValueStructTypes: UnsafePointer<Int8>] = [ValueStructTypes.number : NSNumber.init(value: 0).objCType,
209-
ValueStructTypes.point : NSValue(cgPoint: CGPoint.zero).objCType,
210-
ValueStructTypes.size : NSValue(cgSize: CGSize.zero).objCType,
211-
ValueStructTypes.rect : NSValue(cgRect: CGRect.zero).objCType,
212-
ValueStructTypes.vector : NSValue(cgVector: CGVector(dx: 0.0, dy: 0.0)).objCType,
213-
ValueStructTypes.affineTransform : NSValue(cgAffineTransform: CGAffineTransform.identity).objCType,
214-
ValueStructTypes.transform3D : NSValue.init(caTransform3D: CATransform3DIdentity).objCType
236+
static var valueTypes: [ValueStructTypes: NSValue] = [ValueStructTypes.number : NSNumber.init(value: 0),
237+
ValueStructTypes.point : NSValue(cgPoint: CGPoint.zero),
238+
ValueStructTypes.size : NSValue(cgSize: CGSize.zero),
239+
ValueStructTypes.rect : NSValue(cgRect: CGRect.zero),
240+
ValueStructTypes.vector : NSValue(cgVector: CGVector(dx: 0.0, dy: 0.0)),
241+
ValueStructTypes.affineTransform : NSValue(cgAffineTransform: CGAffineTransform.identity),
242+
ValueStructTypes.transform3D : NSValue.init(caTransform3D: CATransform3DIdentity)
215243
]
216244

217245

218246
/**
219247
* Provides a C string returned by Foundation's `objCType` method for a specific ValueStructTypes type; this represents a specific Objective-C type. This is useful for Foundation structs which can't be used with Swift's `as` type checking.
220248
*/
221249
func toObjCType() -> UnsafePointer<Int8> {
222-
guard let type_value = ValueStructTypes.valueTypes[self] else { return NSNumber(value: false).objCType }
250+
guard let type_value = ValueStructTypes.valueTypes[self]?.objCType else { return NSNumber(value: false).objCType }
223251

224252
return type_value
225253
}

0 commit comments

Comments
 (0)