From 89d72f08276d75f85f23274f58d154c6939b4717 Mon Sep 17 00:00:00 2001 From: Jimmy Lee Date: Mon, 28 May 2012 12:16:22 +1000 Subject: [PATCH] Added ability to add pan gesture recogniser to the top view snapshot. This is useful when you cannot add panGesture to the main view but to a sub view (e.g. navigation bar) instead. --- .../ECSlidingViewController.h | 8 ++++++++ .../ECSlidingViewController.m | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h index a4a4e99..6b2cd01 100644 --- a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h +++ b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.h @@ -114,6 +114,14 @@ typedef enum { */ @property (nonatomic, unsafe_unretained) BOOL shouldAllowUserInteractionsWhenAnchored; +/** Specifies if the top view snapshot requires a pan gesture recognizer. + + This is useful when panGesture is added to the navigation bar instead of the main view. + + By default, this is set to NO + */ +@property (nonatomic, unsafe_unretained) BOOL shouldAddPanGestureRecognizerToTopViewSnapshot; + /** Specifies the behavior for the under left width By default, this is set to ECFullWidth diff --git a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m index 8b27a21..494376a 100644 --- a/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m +++ b/ECSlidingViewController/Vendor/ECSlidingViewController/ECSlidingViewController.m @@ -21,6 +21,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset"; @property (nonatomic, unsafe_unretained) CGFloat initialHoizontalCenter; @property (nonatomic, strong) UIPanGestureRecognizer *panGesture; @property (nonatomic, strong) UITapGestureRecognizer *resetTapGesture; +@property (nonatomic, strong) UIPanGestureRecognizer *topViewSnapshotPanGesture; @property (nonatomic, unsafe_unretained) BOOL underLeftShowing; @property (nonatomic, unsafe_unretained) BOOL underRightShowing; @property (nonatomic, unsafe_unretained) BOOL topViewIsOffScreen; @@ -77,6 +78,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset"; @synthesize underRightWidthLayout = _underRightWidthLayout; @synthesize underLeftWidthLayout = _underLeftWidthLayout; @synthesize shouldAllowUserInteractionsWhenAnchored; +@synthesize shouldAddPanGestureRecognizerToTopViewSnapshot; @synthesize resetStrategy = _resetStrategy; // category properties @@ -88,6 +90,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset"; @synthesize underLeftShowing = _underLeftShowing; @synthesize underRightShowing = _underRightShowing; @synthesize topViewIsOffScreen = _topViewIsOffScreen; +@synthesize topViewSnapshotPanGesture = _topViewSnapshotPanGesture; - (void)setTopViewController:(UIViewController *)theTopViewController { @@ -171,6 +174,7 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset"; { [super viewDidLoad]; self.shouldAllowUserInteractionsWhenAnchored = NO; + self.shouldAddPanGestureRecognizerToTopViewSnapshot = NO; self.resetTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetTopView)]; _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(updateTopViewHorizontalCenterWithRecognizer:)]; self.resetTapGesture.enabled = NO; @@ -426,10 +430,17 @@ NSString *const ECSlidingViewTopDidReset = @"ECSlidingViewTopDidReset"; - (void)addTopViewSnapshot { - if (!self.topViewSnapshot.superview && !self.shouldAllowUserInteractionsWhenAnchored) { - topViewSnapshot.layer.contents = (id)[UIImage imageWithUIView:self.topView].CGImage; - [self.topView addSubview:self.topViewSnapshot]; - } + if (!self.topViewSnapshot.superview && !self.shouldAllowUserInteractionsWhenAnchored) { + topViewSnapshot.layer.contents = (id)[UIImage imageWithUIView:self.topView].CGImage; + + if (self.shouldAddPanGestureRecognizerToTopViewSnapshot) { + if (!_topViewSnapshotPanGesture) { + _topViewSnapshotPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(updateTopViewHorizontalCenterWithRecognizer:)]; + } + [topViewSnapshot addGestureRecognizer:_topViewSnapshotPanGesture]; + } + [self.topView addSubview:self.topViewSnapshot]; + } } - (void)removeTopViewSnapshot