Created
September 22, 2015 20:13
-
-
Save nickfrey/07e2c6d8d2e5444fb91d to your computer and use it in GitHub Desktop.
Test 3D Touch peek/pop using private APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
*/ |
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
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!