@@ -15,6 +15,7 @@ - (void) setRootViewController:(UIViewController*)controller;
1515- (void ) handleShadows ;
1616- (void ) informDelegateWithOptionalSelector : (SEL )selector withParam : (id )param ;
1717- (void ) popViewControllerWithNewCenterController : (UIViewController *)centerController animated : (BOOL )animated andPresentNewController : (UIViewController*)controllerToPush withDirection : (PPRevealSideDirection)direction andOffset : (CGFloat)offset ;
18+ - (void ) addGesturesToCenterController ;
1819- (void ) addPanGestureToController : (UIViewController*)controller ;
1920- (void ) addTapGestureToController : (UIViewController*)controller ;
2021- (void ) addGesturesToController : (UIViewController*)controller ;
@@ -424,6 +425,13 @@ - (void) preloadViewController:(UIViewController*)controller forSide:(PPRevealSi
424425 [_viewControllersOffsets setObject: [NSNumber numberWithFloat: offset] forKey: [NSNumber numberWithInt: direction]];
425426}
426427
428+ - (void ) unloadViewControllerForSide : (PPRevealSideDirection)direction
429+ {
430+ NSNumber *key = [NSNumber numberWithInt: direction];
431+ UIViewController *controller = [_viewControllers objectForKey: key];
432+ [controller.view removeFromSuperview ];
433+ [_viewControllers removeObjectForKey: key];
434+ }
427435
428436- (void ) changeOffset : (CGFloat)offset forDirection : (PPRevealSideDirection)direction {
429437 [self changeOffset: offset forDirection: direction animated: NO ];
@@ -481,21 +489,21 @@ - (void) resetOption:(PPRevealSideOptions)option {
481489- (void ) setPanInteractionsWhenClosed : (PPRevealSideInteractions)panInteractionsWhenClosed {
482490 [self willChangeValueForKey: @" panInteractionsWhenClosed" ];
483491 _panInteractionsWhenClosed = panInteractionsWhenClosed;
484- [self addGesturesToController: _rootViewController ];
492+ [self addGesturesToCenterController ];
485493 [self didChangeValueForKey: @" panInteractionsWhenClosed" ];
486494}
487495
488496- (void ) setPanInteractionsWhenOpened : (PPRevealSideInteractions)panInteractionsWhenOpened {
489497 [self willChangeValueForKey: @" panInteractionsWhenOpened" ];
490498 _panInteractionsWhenOpened = panInteractionsWhenOpened;
491- [self addGesturesToController: _rootViewController ];
499+ [self addGesturesToCenterController ];
492500 [self didChangeValueForKey: @" panInteractionsWhenOpened" ];
493501}
494502
495503- (void ) setTapInteractionsWhenOpened : (PPRevealSideInteractions)tapInteractionsWhenOpened {
496504 [self willChangeValueForKey: @" tapInteractionsWhenOpened" ];
497505 _tapInteractionsWhenOpened = tapInteractionsWhenOpened;
498- [self addGesturesToController: _rootViewController ];
506+ [self addGesturesToCenterController ];
499507 [self didChangeValueForKey: @" tapInteractionsWhenOpened" ];
500508}
501509
@@ -527,7 +535,7 @@ - (void) setRootViewController:(UIViewController *)controller {
527535 [self .view addSubview: _rootViewController.view];
528536 if ([[[UIDevice currentDevice ] systemVersion ] floatValue ] < 5.0 ) [_rootViewController viewDidAppear: NO ];
529537
530- [self addGesturesToController: _rootViewController ];
538+ [self addGesturesToCenterController ];
531539
532540 [self didChangeValueForKey: @" rootViewController" ];
533541 }
@@ -562,7 +570,7 @@ - (void) informDelegateWithOptionalSelector:(SEL)selector withParam:(id)param {
562570 if (selector == @selector (pprevealSideViewController:didPushController: )
563571 ||
564572 selector == @selector (pprevealSideViewController:didPopToController: )) {
565- [self addGesturesToController: _rootViewController ];
573+ [self addGesturesToCenterController ];
566574 }
567575}
568576
@@ -579,21 +587,31 @@ - (void) resizeCurrentView {
579587 }
580588}
581589
590+ - (UIViewController*) getControllerForGestures
591+ {
592+ UIViewController *controllerForGestures = _rootViewController;
593+ if ([self .delegate respondsToSelector: @selector (controllerForGesturesOnPPRevealSideViewController: )]) {
594+ UIViewController *specialController = [self .delegate controllerForGesturesOnPPRevealSideViewController: self ];
595+ if (specialController) controllerForGestures = specialController;
596+ }
597+ return controllerForGestures;
598+ }
599+
582600- (void ) addPanGestureToController : (UIViewController*)controller {
583601
584602 BOOL isClosed = ([self getSideToClose ] == PPRevealSideDirectionNone) ? YES : NO ;
585603 PPRevealSideInteractions interactions = isClosed ? _panInteractionsWhenClosed : _panInteractionsWhenOpened;
586-
587- if (interactions & PPRevealSideInteractionNavigationBar && ([_rootViewController isKindOfClass: [UINavigationController class ]] || _rootViewController .navigationController )) {
604+
605+ if (interactions & PPRevealSideInteractionNavigationBar && ([controller isKindOfClass: [UINavigationController class ]] || controller .navigationController )) {
588606 UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc ] initWithTarget: self
589607 action: @selector (gestureRecognizerDidPan: )];
590608 panGesture.cancelsTouchesInView = YES ;
591609 panGesture.delegate = self;
592610 UINavigationController *nav;
593- if ([_rootViewController isKindOfClass: [UINavigationController class ]])
594- nav = (UINavigationController*)_rootViewController ;
611+ if ([controller isKindOfClass: [UINavigationController class ]])
612+ nav = (UINavigationController*)controller ;
595613 else
596- nav = _rootViewController .navigationController ;
614+ nav = controller .navigationController ;
597615
598616 [nav.navigationBar addGestureRecognizer: panGesture];
599617 [_gestures addObject: panGesture];
@@ -605,14 +623,14 @@ - (void) addPanGestureToController:(UIViewController*)controller {
605623 panGesture.cancelsTouchesInView = YES ;
606624 panGesture.delegate = self;
607625 UIViewController *c;
608- if ([_rootViewController isKindOfClass: [UINavigationController class ]]) {
609- c = [((UINavigationController*)_rootViewController ).viewControllers lastObject ];
626+ if ([controller isKindOfClass: [UINavigationController class ]]) {
627+ c = [((UINavigationController*)controller ).viewControllers lastObject ];
610628 }
611629 else
612- if (_rootViewController .navigationController )
613- c = [_rootViewController .navigationController.viewControllers lastObject ];
630+ if (controller .navigationController )
631+ c = [controller .navigationController.viewControllers lastObject ];
614632 else
615- c = _rootViewController ;
633+ c = controller ;
616634
617635 [c.view addGestureRecognizer: panGesture];
618636 [_gestures addObject: panGesture];
@@ -629,17 +647,16 @@ - (void) addTapGestureToController:(UIViewController *)controller {
629647 return ;
630648 }
631649
632-
633- if (_tapInteractionsWhenOpened & PPRevealSideInteractionNavigationBar && ([_rootViewController isKindOfClass: [UINavigationController class ]] || _rootViewController.navigationController )) {
650+ if (_tapInteractionsWhenOpened & PPRevealSideInteractionNavigationBar && ([controller isKindOfClass: [UINavigationController class ]] || controller.navigationController )) {
634651 UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc ] initWithTarget: self
635652 action: @selector (gestureRecognizerDidTap: )];
636653 tapGesture.cancelsTouchesInView = YES ;
637654 tapGesture.delegate = self;
638655 UINavigationController *nav;
639- if ([_rootViewController isKindOfClass: [UINavigationController class ]])
640- nav = (UINavigationController*)_rootViewController ;
656+ if ([controller isKindOfClass: [UINavigationController class ]])
657+ nav = (UINavigationController*)controller ;
641658 else
642- nav = _rootViewController .navigationController ;
659+ nav = controller .navigationController ;
643660
644661 [nav.navigationBar addGestureRecognizer: tapGesture];
645662 [_gestures addObject: tapGesture];
@@ -652,14 +669,14 @@ - (void) addTapGestureToController:(UIViewController *)controller {
652669 tapGesture.cancelsTouchesInView = YES ;
653670 tapGesture.delegate = self;
654671 UIViewController *c;
655- if ([_rootViewController isKindOfClass: [UINavigationController class ]]) {
656- c = [((UINavigationController*)_rootViewController ).viewControllers lastObject ];
672+ if ([controller isKindOfClass: [UINavigationController class ]]) {
673+ c = [((UINavigationController*)controller ).viewControllers lastObject ];
657674 }
658675 else
659- if (_rootViewController .navigationController )
660- c = [_rootViewController .navigationController.viewControllers lastObject ];
676+ if (controller .navigationController )
677+ c = [controller .navigationController.viewControllers lastObject ];
661678 else
662- c = _rootViewController ;
679+ c = controller ;
663680
664681 [c.view addGestureRecognizer: tapGesture];
665682 [_gestures addObject: tapGesture];
@@ -673,6 +690,11 @@ - (void) addGesturesToController:(UIViewController*)controller {
673690 [self addTapGestureToController: controller];
674691}
675692
693+ - (void ) addGesturesToCenterController
694+ {
695+ [self addGesturesToController: [self getControllerForGestures ]];
696+ }
697+
676698- (void ) removeAllPanGestures {
677699 NSMutableArray *array = [NSMutableArray arrayWithArray: _gestures];
678700 for (UIGestureRecognizer* panGest in array) {
@@ -700,6 +722,11 @@ - (void) removeAllGestures {
700722 [_gestures removeAllObjects ];
701723}
702724
725+ - (void ) updateViewWhichHandleGestures
726+ {
727+ [self addGesturesToCenterController ];
728+ }
729+
703730#pragma mark Closed Controllers
704731
705732- (BOOL ) isLeftControllerClosed {
@@ -846,10 +873,10 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive
846873 else _wasClosed = NO ;
847874
848875 BOOL hasExceptionTouch = NO ;
849- if ([touch.view isKindOfClass: [UIControl class ]]) {
850- if (![touch.view isKindOfClass: NSClassFromString (@" UINavigationButton" )]) hasExceptionTouch = YES ;
851- }
852-
876+ // if ([touch.view isKindOfClass:[UIControl class]]) {
877+ // if (![touch.view isKindOfClass:NSClassFromString(@"UINavigationButton")]) hasExceptionTouch = YES;
878+ // }
879+
853880 BOOL hasExceptionDelegate = NO ;
854881 if ([self .delegate respondsToSelector: @selector (pprevealSideViewController:shouldDeactivateGesture:forView: )])
855882 hasExceptionDelegate = [self .delegate pprevealSideViewController: self
0 commit comments