Skip to content

Accesses all locations in a multitouch pan gesture #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions C4/Core/C4Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public func -= (inout lhs: C4Point, rhs: C4Vector) {
lhs.y -= rhs.y
}

/// Translate a point by the negative of the given vector
///
/// - parameter lhs: a C4Point to translate
/// - parameter rhs: a C4Vector whose values will be applied to the point
public func * (lhs: C4Point, rhs: Int) -> C4Point {
return C4Point(lhs.x * Double(rhs), lhs.y * Double(rhs))
}

/// Calculate the vector between two points
///
/// - parameter lhs: a C4Point
Expand All @@ -142,6 +150,16 @@ public func + (lhs: C4Point, rhs: C4Vector) -> C4Point {
return C4Point(lhs.x + rhs.x,lhs.y + rhs.y)
}

/// Adds two points together.
///
/// - parameter lhs: a C4Point
/// - parameter rhs: a C4Vector
///
/// - returns: A new point whose coordinates are the sum of lhs and rhs
public func + (lhs: C4Point, rhs: C4Point) -> C4Point {
return C4Point(lhs.x + rhs.x,lhs.y + rhs.y)
}

/// Translate a point by the negative of the vector.
///
/// - parameter lhs: a C4Point to translate
Expand Down
14 changes: 10 additions & 4 deletions C4/UI/UIGestureRecognizer+Closure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extension UITapGestureRecognizer {
}


public typealias PanAction = (location: C4Point, translation: C4Vector, velocity: C4Vector, state: UIGestureRecognizerState) -> ()
public typealias PanAction = (location: C4Point, translation: C4Vector, velocity: C4Vector, state: UIGestureRecognizerState, locations: [C4Point]) -> ()

extension UIPanGestureRecognizer {

Expand All @@ -135,7 +135,7 @@ extension UIPanGestureRecognizer {
}

if let action = newValue {
actionHandler = PanGestureHandler(action)
actionHandler = PanGestureHandler(action, referenceView)
addTarget(actionHandler!, action: "handleGesture:")
} else {
actionHandler = nil
Expand Down Expand Up @@ -174,13 +174,19 @@ extension UIPanGestureRecognizer {
/// This class is used as the target of the gesture recognizer action. It forwards the method call to the closure.
internal class PanGestureHandler : NSObject {
let action: PanAction
let referenceView: UIView?

init(_ action: PanAction) {
init(_ action: PanAction, _ view: UIView?) {
self.action = action
self.referenceView = view
}

func handleGesture(gestureRecognizer: UIPanGestureRecognizer) {
action(location: gestureRecognizer.location, translation: gestureRecognizer.translation, velocity: gestureRecognizer.velocity, state: gestureRecognizer.state)
var touches = [C4Point]()
for i in 0..<gestureRecognizer.numberOfTouches() {
touches.append(C4Point(gestureRecognizer.locationOfTouch(i, inView: self.referenceView)))
}
action(location: gestureRecognizer.location, translation: gestureRecognizer.translation, velocity: gestureRecognizer.velocity, state: gestureRecognizer.state, locations: touches)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion C4iOS.xcodeproj/xcshareddata/xcschemes/C4.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down