Skip to content

Instantly share code, notes, and snippets.

Created January 1, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4428748 to your computer and use it in GitHub Desktop.
Save anonymous/4428748 to your computer and use it in GitHub Desktop.
Find the leaks (AKA as - the reason I shot myself in the head)
-(void)swipeDetected:(UIPanGestureRecognizer *)sender
{
CGPoint p = [sender translationInView:self];
CGFloat currentPointY;
CGFloat velocityX = [sender velocityInView:self.superview].x;
p.x += velocityX / SWIPE_THRESHOLD * 10;
if (sender.state == UIGestureRecognizerStateBegan) {
CGFloat currentPointY = p.y;
if (p.x >= 0) {
[self createStatusSwipeBackgroundViewForStatus:@"BUY"];
} else {
[self createStatusSwipeBackgroundViewForStatus:@"SELL"];
}
} else if (sender.state == UIGestureRecognizerStateChanged) {
if (ABS(p.y - currentPointY) > SWIPE_Y_AXIS_THRESHOLD) {
[self handleStopSwipeWithXAxis:p.x];
return;
}
if (p.x > 0) {
[self handleSwipeXAxisChangedFromLeftToRightWithXAxis:p.x];
} else {
[self handleSwipeXAxisChangedFromRightToLeftWithXAxis:p.x];
}
} else if (sender.state == UIGestureRecognizerStateEnded ||
sender.state == UIGestureRecognizerStateFailed ||
sender.state == UIGestureRecognizerStateCancelled) {
[self setStatusActionLinesHidden:NO];
if ([self isActionForSameStatusWithXAxis:p.x]) return;
if (p.x > SWIPE_THRESHOLD) {
[self.delegate cellBuyWithSender:self];
}
if (-1 * p.x > SWIPE_THRESHOLD) {
[self.delegate cellSellWithSender:self];
}
[UIView animateWithDuration:0.4 animations:^{
self.origin = CGPointMake(0, self.origin.y);
if (p.x > 0) {
self.swipeBackgroundImage.origin = CGPointMake(-self.swipeBackgroundImage.width, self.swipeBackgroundImage.origin.y);
} else{
self.swipeBackgroundImage.origin = CGPointMake(self.width, self.swipeBackgroundImage.origin.y);
}
} completion:^(BOOL finished) {
}];
}
}
@sergiocampama
Copy link

is it that you redefined currentPointY in the first if, using a new currentPointY instead of the one in the function scope? Or that you didn't use static on the first currentPointY so when reentering the function currentPointY when sender.state == UIGestureRecognizerStateChanged is undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment