Skip to content

Commit

Permalink
ADD: support for swiping outside image frame to dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
u10int committed Oct 4, 2014
1 parent 86cf9b4 commit 970d7e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ - (void)viewDidLoad {
//self.mediaFocusController.parallaxEnabled = NO; // uncomment if you don't want the parallax (push-back) effect
//self.mediaFocusController.shouldDismissOnTap = NO; // uncomment if you wish to disable dismissing the view on a single tap outside image bounds
//self.mediaFocusController.shouldDismissOnImageTap = YES; // uncomment if you wish to support dismissing view on a single tap on the image itself
//self.mediaFocusController.allowSwipeOnBackgroundView = NO;

self.thumbnailView = [self thumbnailViewWithOrigin:CGPointMake(20.0, 20.0)];
self.thumbnailView.image = [UIImage imageNamed:@"seattle01.jpg"];
Expand Down
3 changes: 3 additions & 0 deletions URBMediaFocusViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
// determines whether or not view should be dismissed when the container view is tapped within bounds of image view
@property (nonatomic, assign) BOOL shouldDismissOnImageTap;

// determines whether or not swiping to dismiss is allowed outside of the image bounds instead of just within the image frame
@property (nonatomic, assign) BOOL allowSwipeOnBackgroundView;

// determines if photo action sheet should appear with a long press on the photo (default NO)
@property (nonatomic, assign) BOOL shouldShowPhotoActions;

Expand Down
9 changes: 8 additions & 1 deletion URBMediaFocusViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (id)init {
self.shouldDismissOnImageTap = NO;
self.shouldShowPhotoActions = NO;
self.shouldRotateToDeviceOrientation = YES;
self.allowSwipeOnBackgroundView = YES;
}
return self;
}
Expand Down Expand Up @@ -164,7 +165,13 @@ - (void)setup {
// pan gesture to handle the physics
self.panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
self.panRecognizer.delegate = self;
[self.imageView addGestureRecognizer:self.panRecognizer];

if (self.allowSwipeOnBackgroundView) {
[self.containerView addGestureRecognizer:self.panRecognizer];
}
else {
[self.imageView addGestureRecognizer:self.panRecognizer];
}

/* UIDynamics stuff */
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
Expand Down

0 comments on commit 970d7e1

Please sign in to comment.