滑动时显示“额外”的UITableView子视图

我正在尝试为我正在创建的应用程序实现“额外”菜单。 基本上我有一个UITableView有多种类型的单元格,当用户在单元格上向左滑动时,我希望能够动态地向他们展示他们可以做的“额外”。 例如,在post上,他们可以滑过,然后查看共享等选项,例如…等。 如果你在ios上使用了Alien Blue app for Reddit,那么这就是我要做的……

到目前为止,我有滑动识别器工作,它正确识别单元格的类型…我只是不知道如何启动子视图编程…

我是否只是将每个单元格放大并隐藏附加内容直到滑动,或者在我去的时候动态地为每个单元格添加视图…

感谢任何建议或帮助

如果需要我可以提供代码….

一个

我认为你是对的,至少,这就是我在我的手机上所做的。

唯一的区别是我没有使单元格宽度大于窗口宽度。 我添加了一个带有额外内容的视图,在我的例子中,它是一个删除按钮,在常规的cell.contentview下。 然后当单元格从右向左检测到滑动时,它将调用一个函数来处理手势。

因为我希望用户在将单元格向左拖动时看到该删除按钮,并在他们将单元格平移到足够远时完全显示该按钮

这是我如何处理平移手势的片段,

CGPoint _originalTouchPoint; - (void)handlePan:(UIPanGestureRecognizer *)recognizer { switch (recognizer.state) { case UIGestureRecognizerStateBegan: //save the original touch point when pan starts _originalTouchPoint = [recognizer locationInView:_tableView]; break; case UIGestureRecognizerStateChanged: [self handlePan:recognizer]; break; case UIGestureRecognizerStateEnded: [self panEnded:recognizer]; break; default: break; } } - (void)handlePan:(UIPanGestureRecognizer *)recognizer { MyCell *ourCell = (MyCell *)recognizer.view; CGPoint touchPoint = [recognizer locationInView:_tableView]; float movedDistance = (_originalTouchPoint.x - touchPoint.x); if(movedDistance < 0) movedDistance = 0; float maxX = ourCell.deleteButton.frame.size.width; float ourTranslation = MAX(-1 * ourCell.deleteButton.frame.size.width, -1 * movedDistance); ourCell.contentView.transform = CGAffineTransformMakeTranslation(ourTranslation, 0.0f); // i only show the button when user pan all the way though _shouldDeleteButtonShow = movedDistance / maxX >= 1.0; } - (void)panEnded:(UIPanGestureRecognizer *)recognizer { MyCell *ourCell = (MyCell *)recognizer.view; if (_shouldDeleteButtonShow) { //do whatever you want in this case } else { //move the cell back to normal [UIView animateWithDuration:0.3 animations:^ { ourCell.contentView.transform = CGAffineTransformIdentity; }]; } } 

这些是我的代码,也许不能完全按照您的意愿工作,但希望这能让您大致了解如何执行此操作