From 84518c9ebdd95c837126137bb0012c609a516b2a Mon Sep 17 00:00:00 2001 From: Pim Coumans Date: Thu, 15 Aug 2019 20:05:33 +0200 Subject: [PATCH 1/2] Forward navigation controller delegate methods --- Classes/SloppySwiper.h | 2 +- Classes/SloppySwiper.m | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Classes/SloppySwiper.h b/Classes/SloppySwiper.h index f02761b..53daafc 100644 --- a/Classes/SloppySwiper.h +++ b/Classes/SloppySwiper.h @@ -13,7 +13,7 @@ @class SloppySwiper; -@protocol SloppySwiperDelegate +@protocol SloppySwiperDelegate @optional // Return NO when you don't want the TabBar to animate during swiping. (Default YES) diff --git a/Classes/SloppySwiper.m b/Classes/SloppySwiper.m index 0b17b84..0eda76b 100644 --- a/Classes/SloppySwiper.m +++ b/Classes/SloppySwiper.m @@ -122,6 +122,9 @@ -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if (operation == UINavigationControllerOperationPop) { return self.animator; } + if ([self.delegate respondsToSelector:@selector(navigationController:animationControllerForOperation:fromViewController:toViewController:)]) { + return [self.delegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC]; + } return nil; } @@ -135,6 +138,10 @@ - (void)navigationController:(UINavigationController *)navigationController will if (animated) { self.duringAnimation = YES; } + + if ([self.delegate respondsToSelector:@selector(navigationController:willShowViewController:animated:)]) { + [self.delegate navigationController:navigationController willShowViewController:viewController animated:animated]; + } } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated @@ -147,6 +154,24 @@ - (void)navigationController:(UINavigationController *)navigationController didS else { self.panRecognizer.enabled = YES; } + + if ([self.delegate respondsToSelector:@selector(navigationController:didShowViewController:animated:)]) { + [self.delegate navigationController:navigationController didShowViewController:viewController animated:animated]; + } +} + +- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController { + if ([self.delegate respondsToSelector:@selector(navigationControllerSupportedInterfaceOrientations:)]) { + return [self.delegate navigationControllerSupportedInterfaceOrientations:navigationController]; + } + return navigationController.supportedInterfaceOrientations; +} + +- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController { + if ([self.delegate respondsToSelector:@selector(navigationControllerPreferredInterfaceOrientationForPresentation:)]) { + return [self.delegate navigationControllerPreferredInterfaceOrientationForPresentation:navigationController]; + } + return navigationController.preferredInterfaceOrientationForPresentation; } @end From 8c39c3da0dcd5b56dea63bf899adca8aa48dc225 Mon Sep 17 00:00:00 2001 From: Pim Coumans Date: Thu, 15 Aug 2019 20:32:51 +0200 Subject: [PATCH 2/2] Fix for infinite call to delegate method when not implemented --- Classes/SloppySwiper.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Classes/SloppySwiper.m b/Classes/SloppySwiper.m index 0eda76b..cc024ac 100644 --- a/Classes/SloppySwiper.m +++ b/Classes/SloppySwiper.m @@ -117,6 +117,17 @@ -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { #pragma mark - UINavigationControllerDelegate +- (BOOL)respondsToSelector:(SEL)selector { + SEL interfaceOrientationsSelector = @selector(navigationControllerSupportedInterfaceOrientations:); + SEL interfaceOrientationsForPresentationSelector = @selector(navigationControllerPreferredInterfaceOrientationForPresentation:); + + // Only use these delegate methods if they can be forwarded + if (selector == interfaceOrientationsSelector || selector == interfaceOrientationsForPresentationSelector) { + return [self.delegate respondsToSelector:selector]; + } + return [super respondsToSelector:selector]; +} + - (id)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC { if (operation == UINavigationControllerOperationPop) {