Skip to content

Instantly share code, notes, and snippets.

@nickfrey
Created September 22, 2015 20:13
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nickfrey/07e2c6d8d2e5444fb91d to your computer and use it in GitHub Desktop.
Save nickfrey/07e2c6d8d2e5444fb91d to your computer and use it in GitHub Desktop.
Test 3D Touch peek/pop using private APIs
@interface UIPreviewForceInteractionProgress : NSObject
- (void)endInteraction:(BOOL)arg1;
@end
@interface UIPreviewInteractionController : NSObject
@property (nonatomic, readonly) UIPreviewForceInteractionProgress *interactionProgressForPresentation;
- (BOOL)startInteractivePreviewAtPosition:(CGPoint)point inView:(UIView *)view;
- (void)cancelInteractivePreview;
- (void)commitInteractivePreview;
@end
@interface _UIViewControllerPreviewSourceViewRecord : NSObject <UIViewControllerPreviewing>
@property (nonatomic, readonly) UIPreviewInteractionController *previewInteractionController;
@end
void WFSimulate3DTouchPreview(id<UIViewControllerPreviewing> previewer, CGPoint sourceLocation) {
_UIViewControllerPreviewSourceViewRecord *record = (_UIViewControllerPreviewSourceViewRecord *)previewer;
UIPreviewInteractionController *interactionController = record.previewInteractionController;
[interactionController startInteractivePreviewAtPosition:sourceLocation inView:record.sourceView];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[interactionController.interactionProgressForPresentation endInteraction:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[interactionController commitInteractivePreview];
//[interactionController cancelInteractivePreview];
});
});
}
/**
How to Use:
(in MyViewController.m:)
id<UIViewControllerPreviewing> previewer = [self registerForPreviewingWithDelegate:self sourceView:self.view];
UICollectionViewCell *cell = [self.collectionView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
WFSimulate3DTouchPreview(previewer, cell.frame.origin);
*/
@nickfrey
Copy link
Author

Note: previewActionItems aren't displayed via this method. It's a bit tough to do so since they're normally brought on screen via a continuous gesture. Open to suggestions!

@SpencerLynn
Copy link

Just a heads up.

startInteractivePreviewAtPosition is now startInteractivePreviewAtLocation

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment