Skip to content

Commit

Permalink
Merge pull request #4 from crenwick/master
Browse files Browse the repository at this point in the history
Tappable is more natural
  • Loading branch information
cconeil committed Mar 29, 2016
2 parents 4f2c86c + e5babcd commit ebe2ffe
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions STP/Tappable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ public extension Tappable where Self:UIView {
let gestureRecognizer = UILongPressGestureRecognizer { [unowned self] (recognizer) -> Void in
let tap = recognizer as! UILongPressGestureRecognizer

func isInFrame() -> Bool {
return CGRectContainsPoint(
CGRectInset(self.frame, self.frame.width * -0.5, self.frame.height * -0.5),
recognizer.locationInView(self)
)
}

switch tap.state {
case .Began:
self.didTouchDown()
case .Ended:
self.didTouchUp()
self.didTap()
if isInFrame() {
self.didTap()
}
case .Failed, .Cancelled:
self.didTouchUp()
default:
break
case .Changed:
if isInFrame() {
self.didTouchDown()
} else {
self.didTouchUp()
}
case .Possible: break
}
}

Expand Down

0 comments on commit ebe2ffe

Please sign in to comment.