通过3D触摸查看和弹出,您如何在偷看期间检测用户平移(如Facebook)?

Dou*_*ith 1 objective-c uiviewcontroller ios ios9 3dtouch

在Facebook应用程序中,如果您"偷看"作为相册一部分的照片,您可以水平滑动手指以转到其他照片.

如何在API中完成?我所看到的只是提供一个视图控制器并在弹出时提交该视图控制器.

Bri*_*hon 8

有一个小技巧,你可以在Peeking时跟踪用户的触摸位置.

您基本上有一个手势识别器,当您开始窥视时开始跟踪用户的触摸位置,并在用户弹出视图控制器或释放他/她的触摸时结束跟踪.应将手势识别器添加到正在显示Peek的视图控制器的视图中.

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

只是一个快速的模型:

@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];
}
Run Code Online (Sandbox Code Playgroud)

我实际上发了一篇博文,其中介绍了这里的机制:https: //medium.com/behancetech/peek-pan-extending-3d-touch-f6520c38fe51#.4xz7lcm9o

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