Skip to content

Commit

Permalink
Vectorial changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustRush committed Aug 23, 2016
1 parent 6dfc020 commit 41e2f06
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Sources/CALayer+AnimateBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -959,15 +959,15 @@ extension CALayer: DriveAnimateBehaviors {
return push
}

private func snapBehavior<T: Vectorial>(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func snapBehavior<T: Vectorial where T.VectorType == CGPoint>(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

return snap
}

private func snapBehavior<T: Vectorial2>(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func snapBehavior<T: Vectorial where T.VectorType == CGRect>(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)
Expand All @@ -976,14 +976,14 @@ extension CALayer: DriveAnimateBehaviors {
return snap
}

private func attachmentBehavior<T: Vectorial>(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func attachmentBehavior<T: Vectorial where T.VectorType == CGPoint>(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<T: Vectorial2>(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func attachmentBehavior<T: Vectorial where T.VectorType == CGRect>(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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/DynamicItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

final class DynamicItem<T: Vectorial>: NSObject, UIDynamicItem {
final class DynamicItem<T: Vectorial where T.VectorType == CGPoint>: NSObject, UIDynamicItem {
var from: T
var to: T
var render: (T) -> Void
Expand Down
2 changes: 1 addition & 1 deletion Sources/DynamicItem2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

//for 4 latitude
final class DynamicItem2<T: Vectorial2>: NSObject, UIDynamicItem {
final class DynamicItem2<T: Vectorial where T.VectorType == CGRect>: NSObject, UIDynamicItem {

var from: T
var to: T
Expand Down
8 changes: 4 additions & 4 deletions Sources/UIView+AnimateBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1005,15 +1005,15 @@ extension UIView: DriveAnimateBehaviors {
return push
}

private func snapBehavior<T: Vectorial>(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func snapBehavior<T: Vectorial where T.VectorType == CGPoint>(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

return snap
}

private func snapBehavior<T: Vectorial2>(damping: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func snapBehavior<T: Vectorial where T.VectorType == CGRect>(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)
Expand All @@ -1022,14 +1022,14 @@ extension UIView: DriveAnimateBehaviors {
return snap
}

private func attachmentBehavior<T: Vectorial>(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func attachmentBehavior<T: Vectorial where T.VectorType == CGPoint>(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<T: Vectorial2>(damping: CGFloat, frequency: CGFloat, from: T, to: T, render: (T) -> Void) -> UIDynamicBehavior {
private func attachmentBehavior<T: Vectorial where T.VectorType == CGRect>(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)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Value+Physical.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions Sources/Vectorial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 41e2f06

Please sign in to comment.