在选中时将滑动视图添加到表格单元格
我有一个dynamic表格视图与单元格从数据库填充。 当一个单元格被选中时,用户应该有可能select其他几个选项。 我知道如何select单元格时推送另一个视图,但我不喜欢这种方法graphics。 例如,如果同一个单元格可以翻转并用滑动显示选项(然后翻转),那可能会更好。 或者整个单元格可能会从屏幕上滑下来显示选项,或者另一个视图可能会从单元格中滑下,然后向后滑动。
哪个解决scheme最容易做到? 任何人都可以指出我正确的方向? 当然,我不需要代码,我只是在这里学习,我只需要知道要看什么。 到目前为止,我已经读了一些关于UITableViewCell的子类,但是,老实说,我还没有得到它。 任何input将不胜感激。
您将使用具有前景和背景视图以及UIPanGestureRecognizer的UITableViewCell子类。 此识别器将触发滑动并处理前景视图的移动。
那么说,你会在这里find一个实现: https : //github.com/spilliams/sparrowlike
重要的一点:
- (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) > 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 > 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 > PAN_CLOSED_X) compare = PAN_CLOSED_X; else if (compare < 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]; } }
- iOS:如何使用AVAssetWriter制作一系列影像
- 如何在Swift中制作Web爬虫
- UILable numberoflines和字体大小在放大时间自动设置
- 在webview或MPMoviePlayerViewController的iOSstreamvideo
- 在NSURLSession中返回错误
- 使用Swift Generics识别子类可以使用自定义类,但不能使用UITapGestureRecognizer
- 默认的UISwitch为YES,然后用NSUserDefaults保存状态
- APNS:didReceiveRemoteNotification:当app在后台时,fetchCompletionHandler没有运行(除非xcode正在调试)
- NSDateFormatter不会格式化奇怪的datestring