-
-
Save anonymous/c51c7cb2997c89094f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)pannedCell:(UIPanGestureRecognizer *)recognizer { | |
if (recognizer.state == UIGestureRecognizerStateBegan) { | |
_firstTouchPoint = [recognizer translationInView:self]; | |
} | |
else if (recognizer.state == UIGestureRecognizerStateChanged) { | |
CGPoint touchPoint = [recognizer translationInView:self]; | |
// Holds the value of how far away (horizontally) from the original resting position the cell has moved | |
CGFloat xPos; | |
// If the first touch point is left of the current point, it means the user is moving his/her finger right and the cell must move right | |
if (_firstTouchPoint.x < touchPoint.x) { | |
xPos = touchPoint.x - _firstTouchPoint.x; | |
if (xPos <= 0) { | |
xPos = 0; | |
} | |
} | |
// User's moving his/her finger left and cell moves left | |
else { | |
xPos = -(_firstTouchPoint.x - touchPoint.x); | |
if (xPos >= 0) { | |
xPos = 0; | |
} | |
} | |
// Only allow the cell to be moved 100 pixels left or right | |
if (xPos <= 100 && xPos >= -100) { | |
// Move our cell to the xPos we defined | |
CGRect slidingViewFrame = self.slidingView.frame; | |
slidingViewFrame.origin = CGPointMake(xPos - 100, 0); | |
self.slidingView.frame = slidingViewFrame; | |
if (xPos >= 80) { | |
if (_removeIconIsActive == NO) { | |
// Change remove icon to a red, active state and animate the change | |
self.removeIconImageView.image = [UIImage imageNamed:@"remove-icon-active.png"]; | |
// [UIView animateWithDuration:0.1 | |
// delay:0.0 | |
// options:UIViewAnimationOptionCurveEaseInOut | |
// animations:^{ | |
// self.removeIconImageView.transform = CGAffineTransformMakeScale(1.3, 1.3); | |
// self.removeIconImageView.image = [UIImage imageNamed:@"remove-icon-active.png"]; | |
// self.removeIconImageView.transform = CGAffineTransformMakeScale(1.0, 1.0); | |
// } | |
// completion:nil | |
// ]; | |
_removeIconIsActive = YES; | |
} | |
CGRect removeIconFrame = self.removeIconImageView.frame; | |
removeIconFrame.origin = CGPointMake(40, 35); | |
self.removeIconImageView.frame = removeIconFrame; | |
} | |
else if (xPos < 80) { | |
if (_removeIconIsActive == YES) { | |
// Change back to inactive state | |
self.removeIconImageView.image = [UIImage imageNamed:@"remove-icon-inactive.png"]; | |
_removeIconIsActive = NO; | |
} | |
CGRect removeIconFrame = self.removeIconImageView.frame; | |
removeIconFrame.origin = CGPointMake(xPos - 40, 35); | |
self.removeIconImageView.frame = removeIconFrame; | |
} | |
if (xPos <= -80) { | |
if (_checkIconIsActive == NO) { | |
// Change check icon to a green, active state and animate the change | |
// [UIView animateWithDuration:0.1 | |
// delay:0.0 | |
// options:UIViewAnimationOptionCurveEaseInOut | |
// animations:^{ | |
// self.checkIconImageView.transform = CGAffineTransformMakeScale(1.3, 1.3); | |
// self.checkIconImageView.image = [UIImage imageNamed:@"check-icon-active.png"]; | |
// self.checkIconImageView.transform = CGAffineTransformMakeScale(1.0, 1.0); | |
// } | |
// completion:nil | |
// ]; | |
_checkIconIsActive = YES; | |
} | |
CGRect checkIconFrame = self.checkIconImageView.frame; | |
checkIconFrame.origin = CGPointMake(270, 35); | |
self.checkIconImageView.frame = checkIconFrame; | |
} | |
else if (xPos > -80) { | |
if (_checkIconIsActive == YES) { | |
// Change back to inactive state | |
self.checkIconImageView.image = [UIImage imageNamed:@"check-icon-inactive.png"]; | |
_checkIconIsActive = NO; | |
} | |
CGRect checkIconFrame = self.checkIconImageView.frame; | |
checkIconFrame.origin = CGPointMake(xPos + 350, 35); | |
self.checkIconImageView.frame = checkIconFrame; | |
} | |
} | |
} | |
else if (recognizer.state == UIGestureRecognizerStateEnded) { | |
[self springBack]; | |
} | |
else if (recognizer.state == UIGestureRecognizerStateCancelled) { | |
[self springBack]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment