I've successfully made it that my UITableViewCell can be slid right and left to mark the cell as read, or to delete it (sort of like how the Reeder app does it) but now it doesn't allow me to simply tap it. How do I allow it to be tapped as well?
I used this article for the structure of the concept, so more information is available there.
I implemented the sliding as follows:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
_firstTouchPoint = [[touches anyObject] locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInView:self];
// Holds the value of how far away from the first touch the finger has moved
CGFloat xPos;
// If the first touch point is left of the current point, it means the user is moving their finger right and the cell must move right
if (_firstTouchPoint.x < touchPoint.x) {
xPos = touchPoint.x - _firstTouchPoint.x;
if (xPos <= 0) {
xPos = 0;
}
}
else {
xPos = -(_firstTouchPoint.x - touchPoint.x);
if (xPos >= 0) {
xPos = 0;
}
}
// Change our cellFront's origin to the xPos we defined
CGRect frame = self.cellFront.frame;
frame.origin = CGPointMake(xPos, 0);
self.cellFront.frame = frame;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self springBack];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self springBack];
}
- (void)springBack {
CGFloat cellXPositionBeforeSpringBack = self.cellFront.frame.origin.x;
CGRect frame = self.cellFront.frame;
frame.origin = CGPointMake(0, 0);
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.cellFront.frame = frame;
} completion:^(BOOL finished) {
}];
if (cellXPositionBeforeSpringBack >= 80 || cellXPositionBeforeSpringBack <= -80) {
NSLog(@"YA");
}
}
When I tap it though, nothing happens.