Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Sep 22, 2015

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

This comment has been minimized.

Copy link

commented Feb 2, 2016

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
You can’t perform that action at this time.