diff --git a/PKRevealController/Controller/PKRevealController.h b/PKRevealController/Controller/PKRevealController.h index 68bf093..8b6237b 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, @@ -39,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. * @@ -127,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 39782f3..70fd82c 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 setFadeMenuesWhileSliding: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]; @@ -817,6 +842,23 @@ - (void)handleGestureBeganWithRecognizer:(UIPanGestureRecognizer *)recognizer - (void)handleGestureChangedWithRecognizer:(UIPanGestureRecognizer *)recognizer { CGPoint currentTouchLocation = [recognizer locationInView:self.view]; + + + if (self.fadeMenuesWhileSliding) + { + 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 +903,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 +1026,14 @@ - (void)showLeftViewControllerAnimated:(BOOL)animated [weakSelf removeRightViewControllerFromHierarchy]; [weakSelf addLeftViewControllerToHierarchy]; + if (weakSelf.fadeMenuesWhileSliding) + { + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.leftViewContainer setAlpha:1.0]; + }]; + } + [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleLeftView] animated:animated completion:^(BOOL finished) @@ -999,6 +1074,14 @@ - (void)showRightViewControllerAnimated:(BOOL)animated [weakSelf removeLeftViewControllerFromHierarchy]; [weakSelf addRightViewControllerToHierarchy]; + if (weakSelf.fadeMenuesWhileSliding) + { + [UIView animateWithDuration:DEFAULT_ANIMATION_DURATION_VALUE + animations:^{ + [weakSelf.rightViewContainer setAlpha:1.0]; + }]; + } + [weakSelf setFrontViewFrame:[weakSelf frontViewFrameForVisibleRightView] animated:animated completion:^(BOOL finished)