From 09c3962b51dcc8bc6605fda5099873bb6c52d2b5 Mon Sep 17 00:00:00 2001 From: Dennis Korkchi Date: Tue, 14 May 2013 13:57:16 +0200 Subject: [PATCH 1/3] Left and Right menu now fades in/out when slided in/out. Also added optional protocol which UIViewControllers can conform to in order to override slide gesture --- .../Controller/PKRevealController.h | 5 ++ .../Controller/PKRevealController.m | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/PKRevealController/Controller/PKRevealController.h b/PKRevealController/Controller/PKRevealController.h index 68bf093..8e7e087 100644 --- a/PKRevealController/Controller/PKRevealController.h +++ b/PKRevealController/Controller/PKRevealController.h @@ -13,6 +13,11 @@ #import #import "UIViewController+PKRevealController.h" + +@protocol PKPanGestureControlProtocol +-(BOOL)allowPanGestureForRecognizer:(UIGestureRecognizer *)gestureRecognizer withTouch:(UITouch *)touch; +@end + typedef NS_ENUM(NSUInteger, PKRevealControllerState) { PKRevealControllerFocusesLeftViewController, diff --git a/PKRevealController/Controller/PKRevealController.m b/PKRevealController/Controller/PKRevealController.m index 39782f3..97c801b 100644 --- a/PKRevealController/Controller/PKRevealController.m +++ b/PKRevealController/Controller/PKRevealController.m @@ -817,6 +817,19 @@ - (void)handleGestureBeganWithRecognizer:(UIPanGestureRecognizer *)recognizer - (void)handleGestureChangedWithRecognizer:(UIPanGestureRecognizer *)recognizer { CGPoint currentTouchLocation = [recognizer locationInView:self.view]; + + + if ([self isLeftViewVisible]) + { + float newAlpha = currentTouchLocation.x/self.leftViewWidthRange.length; + [self.leftViewContainer setAlpha:newAlpha]; + } + else if ([self isRightViewVisible]) + { + float newAlpha = currentTouchLocation.x/self.rightViewWidthRange.length; + [self.rightViewContainer setAlpha:newAlpha]; + } + CGFloat delta = currentTouchLocation.x - self.previousTouchLocation.x; self.previousTouchLocation = currentTouchLocation; @@ -861,6 +874,31 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer return YES; } +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch +{ + BOOL allowGesture = YES; + + UIViewController* visibleVC = self.frontViewController; + + if ([self.frontViewController isKindOfClass:[UINavigationController class]]) + { + UINavigationController* navController = (UINavigationController*)self.frontViewController; + visibleVC = navController.visibleViewController; + } + + if ([visibleVC conformsToProtocol:@protocol(PKPanGestureControlProtocol)] && + !([self isLeftViewVisible] || [self isRightViewVisible]) ) + { + UIViewController* vcProtocol = + (UIViewController *)visibleVC; + + allowGesture = [vcProtocol allowPanGestureForRecognizer:gestureRecognizer withTouch:touch]; + } + + return allowGesture; +} + + #pragma mark - Translation - (void)translateViewsBy:(CGFloat)delta animationType:(PKRevealControllerAnimationType)animationType @@ -959,6 +997,11 @@ - (void)showLeftViewControllerAnimated:(BOOL)animated [weakSelf removeRightViewControllerFromHierarchy]; [weakSelf addLeftViewControllerToHierarchy]; + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.leftViewContainer setAlpha:1.0]; + }]; + [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleLeftView] animated:animated completion:^(BOOL finished) @@ -999,6 +1042,11 @@ - (void)showRightViewControllerAnimated:(BOOL)animated [weakSelf removeLeftViewControllerFromHierarchy]; [weakSelf addRightViewControllerToHierarchy]; + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.rightViewContainer setAlpha:1.0]; + }]; + [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleRightView] animated:animated completion:^(BOOL finished) From 08ab9dfdfbf7e82ca083f64cc4abf06fbdae97a8 Mon Sep 17 00:00:00 2001 From: Dennis Korkchi Date: Tue, 14 May 2013 15:41:12 +0200 Subject: [PATCH 2/3] Converted fade menues while sliding into property, defaults to NO --- .../Controller/PKRevealController.h | 10 +++ .../Controller/PKRevealController.m | 69 ++++++++++++++----- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/PKRevealController/Controller/PKRevealController.h b/PKRevealController/Controller/PKRevealController.h index 8e7e087..8b6237b 100644 --- a/PKRevealController/Controller/PKRevealController.h +++ b/PKRevealController/Controller/PKRevealController.h @@ -44,6 +44,15 @@ typedef NS_OPTIONS(NSUInteger, PKRevealControllerType) * List of option keys that can be passed in the options dictionary. */ +/* + * Determines whether the left and right side menues should fade in/out when being slided + * + * @default NO + * @value NSNumber containing BOOL + */ +extern NSString * const PKRevealControllerFadeMenuesWhileSlidingKey; + + /* * Animation duration for automatic front view movement. * @@ -132,6 +141,7 @@ typedef void(^PKDefaultErrorHandler)(NSError *error); @property (nonatomic, assign, readwrite) PKRevealControllerAnimationType animationType; @property (nonatomic, assign, readwrite) CGFloat quickSwipeVelocity; @property (nonatomic, assign, readwrite) BOOL allowsOverdraw; +@property (nonatomic, assign, readwrite) BOOL fadeMenuesWhileSliding; @property (nonatomic, assign, readwrite) BOOL disablesFrontViewInteraction; @property (nonatomic, assign, readwrite) BOOL recognizesPanningOnFrontView; @property (nonatomic, assign, readwrite) BOOL recognizesResetTapOnFrontView; diff --git a/PKRevealController/Controller/PKRevealController.m b/PKRevealController/Controller/PKRevealController.m index 97c801b..1f62c7b 100644 --- a/PKRevealController/Controller/PKRevealController.m +++ b/PKRevealController/Controller/PKRevealController.m @@ -20,6 +20,7 @@ #define DEFAULT_ALLOWS_OVERDRAW_VALUE YES #define DEFAULT_ANIMATION_TYPE_VALUE PKRevealControllerAnimationTypeStatic #define DEFAULT_QUICK_SWIPE_TOGGLE_VELOCITY_VALUE 800.0f +#define DEFAULT_FADE_MENUES_WHILE_SLIDING NO #define DEFAULT_DISABLES_FRONT_VIEW_INTERACTION_VALUE YES #define DEFAULT_RECOGNIZES_PAN_ON_FRONT_VIEW_VALUE YES #define DEFAULT_RECOGNIZES_RESET_TAP_ON_FRONT_VIEW_VALUE YES @@ -52,6 +53,7 @@ @interface PKRevealController () @implementation PKRevealController +NSString * const PKRevealControllerFadeMenuesWhileSlidingKey = @"PKRevealControllerFadeMenuesWhileSlidingKey"; NSString * const PKRevealControllerAnimationDurationKey = @"PKRevealControllerAnimationDurationKey"; NSString * const PKRevealControllerAnimationCurveKey = @"PKRevealControllerAnimationCurveKey"; NSString * const PKRevealControllerAnimationTypeKey = @"PKRevealControllerAnimationTypeKey"; @@ -704,6 +706,29 @@ - (CGFloat)quickSwipeVelocity #pragma mark - +- (BOOL)fadeMenuesWhileSliding +{ + NSNumber *number = [self.controllerOptions objectForKey:PKRevealControllerFadeMenuesWhileSlidingKey]; + + if (number == nil) + { + [self setDisablesFrontViewInteraction:DEFAULT_FADE_MENUES_WHILE_SLIDING]; + return [self fadeMenuesWhileSliding]; + } + else + { + return [number boolValue]; + } +} + +- (void)setFadeMenuesWhileSliding:(BOOL)fadeMenuesWhileSliding +{ + [self.controllerOptions setObject:[NSNumber numberWithBool:fadeMenuesWhileSliding] + forKey:PKRevealControllerFadeMenuesWhileSlidingKey]; +} + + + - (BOOL)disablesFrontViewInteraction { NSNumber *number = [self.controllerOptions objectForKey:PKRevealControllerDisablesFrontViewInteractionKey]; @@ -819,17 +844,21 @@ - (void)handleGestureChangedWithRecognizer:(UIPanGestureRecognizer *)recognizer CGPoint currentTouchLocation = [recognizer locationInView:self.view]; - if ([self isLeftViewVisible]) - { - float newAlpha = currentTouchLocation.x/self.leftViewWidthRange.length; - [self.leftViewContainer setAlpha:newAlpha]; - } - else if ([self isRightViewVisible]) + if (self.fadeMenuesWhileSliding) { - float newAlpha = currentTouchLocation.x/self.rightViewWidthRange.length; - [self.rightViewContainer setAlpha:newAlpha]; + if ([self isLeftViewVisible]) + { + float newAlpha = currentTouchLocation.x/self.leftViewWidthRange.length; + [self.leftViewContainer setAlpha:newAlpha]; + } + else if ([self isRightViewVisible]) + { + float newAlpha = currentTouchLocation.x/self.rightViewWidthRange.length; + [self.rightViewContainer setAlpha:newAlpha]; + } } + CGFloat delta = currentTouchLocation.x - self.previousTouchLocation.x; self.previousTouchLocation = currentTouchLocation; @@ -997,10 +1026,13 @@ - (void)showLeftViewControllerAnimated:(BOOL)animated [weakSelf removeRightViewControllerFromHierarchy]; [weakSelf addLeftViewControllerToHierarchy]; - [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE - animations:^{ - [weakSelf.leftViewContainer setAlpha:1.0]; - }]; + if (weakSelf.fadeMenuesWhileSliding) + { + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.leftViewContainer setAlpha:1.0]; + }]; + } [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleLeftView] animated:animated @@ -1042,11 +1074,14 @@ - (void)showRightViewControllerAnimated:(BOOL)animated [weakSelf removeLeftViewControllerFromHierarchy]; [weakSelf addRightViewControllerToHierarchy]; - [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE - animations:^{ - [weakSelf.rightViewContainer setAlpha:1.0]; - }]; - + if (weakSelf.fadeMenuesWhileSliding) + { + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.rightViewContainer setAlpha:1.0]; + }]; + } + [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleRightView] animated:animated completion:^(BOOL finished) From a34c9eae7e7f2648b9a1a099e4a58508b7b310f0 Mon Sep 17 00:00:00 2001 From: Dennis Korkchi Date: Tue, 14 May 2013 15:56:03 +0200 Subject: [PATCH 3/3] typo bugfix --- PKRevealController/Controller/PKRevealController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKRevealController/Controller/PKRevealController.m b/PKRevealController/Controller/PKRevealController.m index 1f62c7b..70fd82c 100644 --- a/PKRevealController/Controller/PKRevealController.m +++ b/PKRevealController/Controller/PKRevealController.m @@ -712,7 +712,7 @@ - (BOOL)fadeMenuesWhileSliding if (number == nil) { - [self setDisablesFrontViewInteraction:DEFAULT_FADE_MENUES_WHILE_SLIDING]; + [self setFadeMenuesWhileSliding:DEFAULT_FADE_MENUES_WHILE_SLIDING]; return [self fadeMenuesWhileSliding]; } else