diff --git a/Source/XHImageViewer.m b/Source/XHImageViewer.m index 4de35d6..0552a17 100644 --- a/Source/XHImageViewer.m +++ b/Source/XHImageViewer.m @@ -18,6 +18,8 @@ @interface XHImageViewer () @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; @@ -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 @@ -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; @@ -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);