随着3D触摸偷看和stream行,你如何检测用户平移过程中(如Facebook)?

在Facebook应用程序中,如果您“窥视”作为相册一部分的照片,则可以水平滑动手指以转到其他照片。

这在API中如何完成? 我所看到的全部是提供一个视图控制器,并提交popup视图控制器。

有一个小窍门,你可以跟踪用户的触摸位置,而偷看。

你基本上有一个手势识别器,当你开始查看时开始跟踪用户的触摸位置,一旦用户popup视图控制器或释放他/她的触摸,结束跟踪。 应该将手势识别器添加到引发Peek的视图控制器的视图中。

由于您可以访问Peeked视图控制器,因此您可以从视图控制器调用与用户的触摸位置相关的function。

只是一个快速的模型:

@property (nonatomic, weak, nullable) ViewControllerClass *peekedVC; - (void)handleGestureRecognizer:(UIPanGestureRecognizer *)gr { if (peekedVC && gr.state == UIGestureRecognizerStateChanged) { CGPoint point = [gr locationInView:self.view]; [peekedVC handle:point.x]; } } - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location { NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location]; UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath]; [previewContext setSourceRect:cell.frame]; ViewControllerClass *vc = [ViewControllerClass new]; self.peekedVC = vc; return vc; } - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit { self.peekedVC = nil; [self showViewController:viewControllerToCommit sender:self]; } 

我其实做了一篇博客文章,其中涵盖了这里的机制: https : //medium.com/behancetech/peek-pan-extending-3d-touch-f6520c38fe51#.4xz7lcm9o

还有一个开源项目,可以帮助你整合到这里: https : //github.com/adobe-behancemobile/PeekPan