diff --git a/Sources/CALayer+AnimateBehavior.swift b/Sources/CALayer+AnimateBehavior.swift index b905754..2680dd1 100644 --- a/Sources/CALayer+AnimateBehavior.swift +++ b/Sources/CALayer+AnimateBehavior.swift @@ -959,7 +959,7 @@ extension CALayer: DriveAnimateBehaviors { return push } - private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem(from: from, to: to, render: render) let snap = item.snapBehavior(item.toP, damping: damping) item.behavior = snap @@ -967,7 +967,7 @@ extension CALayer: DriveAnimateBehaviors { return snap } - private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem2(from: from, to: to, render: render) let point = CGPointMake(0.0, item.referenceChangeLength) let snap = item.snapBehavior(point, damping: damping) @@ -976,14 +976,14 @@ extension CALayer: DriveAnimateBehaviors { return snap } - private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem(from: from, to: to, render: render) let attachment = item.attachmentBehavior(item.toP, length: 0.0, damping: damping, frequency: frequency) item.behavior = attachment return attachment } - private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem2(from: from, to: to, render: render) let point = CGPointMake(0.0, item.referenceChangeLength) let attachment = item.attachmentBehavior(point, length: 0.0, damping: damping, frequency: frequency) diff --git a/Sources/DynamicItem.swift b/Sources/DynamicItem.swift index ef5c817..ce11ae1 100644 --- a/Sources/DynamicItem.swift +++ b/Sources/DynamicItem.swift @@ -8,7 +8,7 @@ import UIKit -final class DynamicItem: NSObject, UIDynamicItem { +final class DynamicItem: NSObject, UIDynamicItem { var from: T var to: T var render: (T) -> Void diff --git a/Sources/DynamicItem2.swift b/Sources/DynamicItem2.swift index 0f227eb..2e1e8c8 100644 --- a/Sources/DynamicItem2.swift +++ b/Sources/DynamicItem2.swift @@ -9,7 +9,7 @@ import UIKit //for 4 latitude -final class DynamicItem2: NSObject, UIDynamicItem { +final class DynamicItem2: NSObject, UIDynamicItem { var from: T var to: T diff --git a/Sources/UIView+AnimateBehavior.swift b/Sources/UIView+AnimateBehavior.swift index 37ecc9e..a2b93c9 100644 --- a/Sources/UIView+AnimateBehavior.swift +++ b/Sources/UIView+AnimateBehavior.swift @@ -1005,7 +1005,7 @@ extension UIView: DriveAnimateBehaviors { return push } - private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem(from: from, to: to, render: render) let snap = item.snapBehavior(item.toP, damping: damping) item.behavior = snap @@ -1013,7 +1013,7 @@ extension UIView: DriveAnimateBehaviors { return snap } - private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func snapBehavior(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem2(from: from, to: to, render: render) let point = CGPointMake(0.0, item.referenceChangeLength) let snap = item.snapBehavior(point, damping: damping) @@ -1022,14 +1022,14 @@ extension UIView: DriveAnimateBehaviors { return snap } - private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem(from: from, to: to, render: render) let attachment = item.attachmentBehavior(item.toP, length: 0.0, damping: damping, frequency: frequency) item.behavior = attachment return attachment } - private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { + private func attachmentBehavior(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior { let item = DynamicItem2(from: from, to: to, render: render) let point = CGPointMake(0.0, item.referenceChangeLength) let attachment = item.attachmentBehavior(point, length: 0.0, damping: damping, frequency: frequency) diff --git a/Sources/Value+Physical.swift b/Sources/Value+Physical.swift index 6b37be0..a6530fa 100644 --- a/Sources/Value+Physical.swift +++ b/Sources/Value+Physical.swift @@ -344,7 +344,7 @@ extension CGPoint: Physical, Vectorial, Interpolatable { } } -extension CGRect: Physical, Vectorial2, Interpolatable { +extension CGRect: Physical, Vectorial, Interpolatable { public func fallTo(to: CGRect,magnitude: Double = 1.0, render: (CGRect) -> Void, completion: (() -> Void)? = nil) { let item = DynamicItemGravity(from: self, to: to, render: render) @@ -419,7 +419,7 @@ extension CGRect: Physical, Vectorial2, Interpolatable { } } -extension UIColor: Physical, Vectorial2, Interpolatable { +extension UIColor: Physical, Vectorial, Interpolatable { public func fallTo(to: UIColor,magnitude: Double = 1.0, render: (UIColor) -> Void, completion: (() -> Void)? = nil) { let item = DynamicItemGravity(from: self, to: to, render: render) diff --git a/Sources/Vectorial.swift b/Sources/Vectorial.swift index fecaa6c..0df78e1 100644 --- a/Sources/Vectorial.swift +++ b/Sources/Vectorial.swift @@ -9,11 +9,7 @@ import UIKit protocol Vectorial { - func convert(p: CGPoint) -> Self - func reverse() -> CGPoint -} - -protocol Vectorial2 { - func convert(r: CGRect) -> Self - func reverse() -> CGRect + associatedtype VectorType + func convert(p: VectorType) -> Self + func reverse() -> VectorType } \ No newline at end of file diff --git a/StellarDemo/StellarDemo.xcodeproj/project.xcworkspace/xcuserdata/August.xcuserdatad/UserInterfaceState.xcuserstate b/StellarDemo/StellarDemo.xcodeproj/project.xcworkspace/xcuserdata/August.xcuserdatad/UserInterfaceState.xcuserstate index 7398600..e98d6f8 100644 Binary files a/StellarDemo/StellarDemo.xcodeproj/project.xcworkspace/xcuserdata/August.xcuserdatad/UserInterfaceState.xcuserstate and b/StellarDemo/StellarDemo.xcodeproj/project.xcworkspace/xcuserdata/August.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/CALayer+Stellar.swift b/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/CALayer+Stellar.swift index 13ff0c2..6c95ee1 100644 --- a/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/CALayer+Stellar.swift +++ b/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/CALayer+Stellar.swift @@ -10,6 +10,8 @@ import UIKit extension CALayer: BasicConfigurable1, SnapConfigurable1, AttachmentConfigurable1, GravityConfigurable1, StepControllable { + typealias AnimationItem = CALayer + //MARK: animation methods public func moveTo(point: CGPoint) -> CALayer { let type = AnimationType(type: .Basic, subType: .MoveTo(point))