Skip to content
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

disable pan gesture while animating #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions Source/XHImageViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ @interface XHImageViewer () <UIScrollViewDelegate>

@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) NSArray *imgViews;
@property(nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;


@property(nonatomic, copy) WillDismissWithSelectedViewBlock willDismissWithSelectedViewBlock;
@property(nonatomic, copy) DidDismissWithSelectedViewBlock didDismissWithSelectedViewBlock;
Expand Down Expand Up @@ -62,18 +64,13 @@ - (void)showWithImageViews:(NSArray *)views
- (void)_setup {
self.backgroundColor = [UIColor colorWithWhite:0.1 alpha:1];
self.backgroundScale = 0.95;

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)];
panGestureRecognizer.maximumNumberOfTouches = 1;
[self addGestureRecognizer:panGestureRecognizer];
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)];
_panGestureRecognizer.maximumNumberOfTouches = 1;
[self addGestureRecognizer:_panGestureRecognizer];
}

- (id)init {
self = [self initWithFrame:CGRectZero];
if (self) {
[self _setup];
}
return self;
return [self initWithFrame:CGRectZero];
}

- (id)initWithImageViewerWillDismissWithSelectedViewBlock:(WillDismissWithSelectedViewBlock)willDismissWithSelectedViewBlock
Expand Down Expand Up @@ -185,6 +182,7 @@ - (void)showWithSelectedView:(UIImageView *)selectedView {
[window convertRect:selectedView.frame fromView:selectedView.superview];
[window addSubview:selectedView];

_panGestureRecognizer.enabled = NO;
[UIView animateWithDuration:0.3
animations:^{
_scrollView.alpha = 1;
Expand All @@ -202,6 +200,7 @@ - (void)showWithSelectedView:(UIImageView *)selectedView {
CGRectMake((fullW - W) / 2, (fullH - H) / 2, W, H);
}
completion:^(BOOL finished) {
_panGestureRecognizer.enabled = YES;
_scrollView.contentSize = CGSizeMake(_imgViews.count * fullW, 0);
_scrollView.contentOffset = CGPointMake(currentPage * fullW, 0);

Expand Down