Skip to content

Share sheet #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions BFRImageViewController/BFRImageContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ - (UIImageView *)createImageView {
[resizableImageView setUserInteractionEnabled:YES];
[resizableImageView addGestureRecognizer:singleImgTap];

//Recent the image on double tap
//Reset the image on double tap
UITapGestureRecognizer *doubleImgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recenterImageOriginOrZoomToPoint:)];
doubleImgTap.numberOfTapsRequired = 2;
[resizableImageView addGestureRecognizer:doubleImgTap];

//Share options
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showActivitySheet:)];
[resizableImageView addGestureRecognizer:longPress];

//Ensure the single tap doesn't fire when a user attempts to double tap
[singleImgTap requireGestureRecognizerToFail:doubleImgTap];
[singleImgTap requireGestureRecognizerToFail:longPress];

//Dragging to dismiss
UIPanGestureRecognizer *panImg = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleDrag:)];
Expand Down Expand Up @@ -244,7 +249,7 @@ - (void)recenterImageOriginOrZoomToPoint:(UITapGestureRecognizer *)tap {
}


#pragma mark - Dragging Methods
#pragma mark - Dragging and Long Press Methods
/*! This method has three different states due to the gesture recognizer. In them, we either add the required behaviors using UIDynamics, update the image's position based off of the touch points of the drag, or if it's ended we snap it back to the center or dismiss this view controller if the vertical offset meets the requirements. */
- (void)handleDrag:(UIPanGestureRecognizer *)recognizer {

Expand Down Expand Up @@ -290,6 +295,26 @@ - (void)handleDrag:(UIPanGestureRecognizer *)recognizer {
}
}

- (void)showActivitySheet:(UILongPressGestureRecognizer *)longPress {

UIActivityViewController *activityVC;
if (longPress.state == UIGestureRecognizerStateBegan) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[self.imgLoaded] applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
} else {
activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[self.imgLoaded] applicationActivities:nil];
activityVC.modalPresentationStyle = UIModalPresentationPopover;
activityVC.preferredContentSize = CGSizeMake(320,400);
UIPopoverPresentationController *popoverVC = activityVC.popoverPresentationController;
popoverVC.sourceView = self.imgView;
CGPoint touchPoint = [longPress locationInView:self.imgView];
popoverVC.sourceRect = CGRectMake(touchPoint.x, touchPoint.y, 1, 1);
[self presentViewController:activityVC animated:YES completion:nil];
}
}
}

#pragma mark - Image Asset Retrieval
- (void)retrieveImageFromAsset {
if (![self.imgSrc isKindOfClass:[PHAsset class]]) {
Expand Down