Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You would use a UITableViewCell subclass with a foreground and a background view and a UIPanGestureRecognizer. this recognizer will trigger the swipe and handles the moving of the foreground view.</p> <p>that said, you'll find a implementation here: <a href="https://github.com/spilliams/sparrowlike">https://github.com/spilliams/sparrowlike</a></p> <p>the important bits:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [panGestureRecognizer setDelegate:self]; [cell addGestureRecognizer:panGestureRecognizer]; return cell; } #pragma mark - Gesture recognizer delegate - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer { CustomCell *cell = (CustomCell *)[panGestureRecognizer view]; CGPoint translation = [panGestureRecognizer translationInView:[cell superview] ]; return (fabs(translation.x) / fabs(translation.y) &gt; 1) ? YES : NO; } #pragma mark - Gesture handlers -(void)handlePan:(UIPanGestureRecognizer *)panGestureRecognizer { float threshold = (PAN_OPEN_X+PAN_CLOSED_X)/2.0; float vX = 0.0; float compare; NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell *)[panGestureRecognizer view] ]; UIView *view = ((CustomCell *)panGestureRecognizer.view).frontView; switch ([panGestureRecognizer state]) { case UIGestureRecognizerStateBegan: if (self.openCellIndexPath.section != indexPath.section || self.openCellIndexPath.row != indexPath.row) { [self snapView:((CustomCell *)[self.tableView cellForRowAtIndexPath:self.openCellIndexPath]).frontView toX:PAN_CLOSED_X animated:YES]; [self setOpenCellIndexPath:nil]; [self setOpenCellLastTX:0]; } break; case UIGestureRecognizerStateEnded: vX = (FAST_ANIMATION_DURATION/2.0)*[panGestureRecognizer velocityInView:self.view].x; compare = view.transform.tx + vX; if (compare &gt; threshold) { [self snapView:view toX:PAN_CLOSED_X animated:YES]; [self setOpenCellIndexPath:nil]; [self setOpenCellLastTX:0]; } else { [self snapView:view toX:PAN_OPEN_X animated:YES]; [self setOpenCellIndexPath:[self.tableView indexPathForCell:(CustomCell *)panGestureRecognizer.view] ]; [self setOpenCellLastTX:view.transform.tx]; } break; case UIGestureRecognizerStateChanged: compare = self.openCellLastTX+[panGestureRecognizer translationInView:self.view].x; if (compare &gt; PAN_CLOSED_X) compare = PAN_CLOSED_X; else if (compare &lt; PAN_OPEN_X) compare = PAN_OPEN_X; [view setTransform:CGAffineTransformMakeTranslation(compare, 0)]; break; default: break; } } -(void)snapView:(UIView *)view toX:(float)x animated:(BOOL)animated { if (animated) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; [UIView setAnimationDuration:FAST_ANIMATION_DURATION]; } [view setTransform:CGAffineTransformMakeTranslation(x, 0)]; if (animated) { [UIView commitAnimations]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload