Skip to content
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

Gesture recognition fix #17

Merged
merged 1 commit into from
Dec 22, 2015
Merged
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
21 changes: 11 additions & 10 deletions Source/UIView+draggable.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ - (void)setDraggingEndedBlock:(void (^)())draggingEndedBlock {
- (void)handlePan:(UIPanGestureRecognizer*)sender {
// Check to make you drag from dragging area
CGPoint locationInView = [sender locationInView:self];
if (!CGRectContainsPoint(self.handle, locationInView)) {
if (!CGRectContainsPoint(self.handle, locationInView)
&& sender.state == UIGestureRecognizerStateBegan) {
return;
}

Expand All @@ -97,33 +98,33 @@ - (void)handlePan:(UIPanGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateBegan && self.draggingStartedBlock) {
self.draggingStartedBlock();
}

if (sender.state == UIGestureRecognizerStateEnded && self.draggingEndedBlock) {
self.layer.anchorPoint = CGPointMake(0.5, 0.5);
self.draggingEndedBlock();
}

CGPoint translation = [sender translationInView:[self superview]];

CGFloat newXOrigin = CGRectGetMinX(self.frame) + (([self shouldMoveAlongX]) ? translation.x : 0);
CGFloat newYOrigin = CGRectGetMinY(self.frame) + (([self shouldMoveAlongY]) ? translation.y : 0);

CGRect cagingArea = self.cagingArea;

CGFloat cagingAreaOriginX = CGRectGetMinX(cagingArea);
CGFloat cagingAreaOriginY = CGRectGetMinY(cagingArea);

CGFloat cagingAreaRightSide = cagingAreaOriginX + CGRectGetWidth(cagingArea);
CGFloat cagingAreaBottomSide = cagingAreaOriginY + CGRectGetHeight(cagingArea);

if (!CGRectEqualToRect(cagingArea, CGRectZero)) {

// Check to make sure the view is still within the caging area
if (newXOrigin <= cagingAreaOriginX ||
newYOrigin <= cagingAreaOriginY ||
newXOrigin + CGRectGetWidth(self.frame) >= cagingAreaRightSide ||
newYOrigin + CGRectGetHeight(self.frame) >= cagingAreaBottomSide) {

// Don't move
newXOrigin = CGRectGetMinX(self.frame);
newYOrigin = CGRectGetMinY(self.frame);
Expand Down