From a2d501f57b63f0b4db94f0209ccd49c1095ccda1 Mon Sep 17 00:00:00 2001 From: "yun.chen" Date: Tue, 1 Sep 2015 17:50:44 +0800 Subject: [PATCH] add fd_fullscreenPopGestureRecognizerDelegate Let developer can hook fd_fullscreenPopGestureRecognizer --- ...igationController+FDFullscreenPopGesture.h | 3 +- ...igationController+FDFullscreenPopGesture.m | 59 ++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h index 1be8de7..00851cb 100644 --- a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h +++ b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h @@ -33,7 +33,8 @@ /// The gesture recognizer that actually handles interactive pop. @property (nonatomic, strong, readonly) UIPanGestureRecognizer *fd_fullscreenPopGestureRecognizer; - +/// Don't set gestureRecognizer delegate directly. Use this property instead. +@property (nonatomic, weak) id fd_fullscreenPopGestureRecognizerDelegate; /// A view controller is able to control navigation bar's appearance by itself, /// rather than a global way, checking "fd_prefersNavigationBarHidden" property. /// Default to YES, disable it if you don't want so. diff --git a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m index 914f217..0066521 100644 --- a/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m +++ b/FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.m @@ -26,13 +26,20 @@ @interface _FDFullscreenPopGestureRecognizerDelegate : NSObject @property (nonatomic, weak) UINavigationController *navigationController; - +@property (nonatomic, weak) id delegate; @end @implementation _FDFullscreenPopGestureRecognizerDelegate - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer { + if (self.delegate && [self.delegate respondsToSelector:@selector(gestureRecognizerShouldBegin:)]) { + BOOL shouldBegin = [self.delegate gestureRecognizerShouldBegin:gestureRecognizer]; + if (shouldBegin == NO) { + return shouldBegin; + } + } + // Ignore when no view controller is pushed into the navigation stack. if (self.navigationController.viewControllers.count <= 1) { return NO; @@ -65,6 +72,46 @@ - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer return YES; } +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + if (self.delegate && + [self.delegate respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) { + return [self.delegate gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer]; + } + + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + if (self.delegate && + [self.delegate respondsToSelector:@selector(gestureRecognizer:shouldRequireFailureOfGestureRecognizer:)]) { + return [self.delegate gestureRecognizer:gestureRecognizer shouldRequireFailureOfGestureRecognizer:otherGestureRecognizer]; + } + + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + if (self.delegate && + [self.delegate respondsToSelector:@selector(gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:)]) { + return [self.delegate gestureRecognizer:gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:otherGestureRecognizer]; + } + + return NO; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch +{ + if (self.delegate && + [self.delegate respondsToSelector:@selector(gestureRecognizer:shouldReceiveTouch:)]) { + return [self.delegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch]; + } + + return YES; +} + @end typedef void (^_FDViewControllerWillAppearInjectBlock)(UIViewController *viewController, BOOL animated); @@ -237,6 +284,16 @@ - (void)setFd_viewControllerBasedNavigationBarAppearanceEnabled:(BOOL)enabled objc_setAssociatedObject(self, key, @(enabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +- (id)fd_fullscreenPopGestureRecognizerDelegate +{ + return self.fd_popGestureRecognizerDelegate.delegate; +} + +- (void)setFd_fullscreenPopGestureRecognizerDelegate:(id)fd_fullscreenPopGestureRecognizerDelegate +{ + self.fd_popGestureRecognizerDelegate.delegate = fd_fullscreenPopGestureRecognizerDelegate; +} + @end @implementation UIViewController (FDFullscreenPopGesture)