Permalink
Browse files

Changing the default gestureController to be the centerpanel

  • Loading branch information...
1 parent 0ac1336 commit 070a89fbef2ff12b125a581872fd454b401990e0 @gotosleep committed Mar 19, 2012
Showing with 29 additions and 12 deletions.
  1. +29 −12 JASidePanels/Source/JASidePanelController.m
@@ -30,6 +30,9 @@ - (void)_sizeSidePanels;
// center panel
- (void)_swapCenter:(UIViewController *)previous with:(UIViewController *)next;
+// buttons
+- (void)_placeButtonForLeftPanel;
+
// internal helpers
- (BOOL)_validateThreshold:(CGFloat)movement;
@@ -243,7 +246,9 @@ - (void)_sizeSidePanels {
- (void)setCenterPanel:(UIViewController *)centerPanel {
UIViewController *previous = _centerPanel;
if (centerPanel != _centerPanel) {
+ [_centerPanel removeObserver:self forKeyPath:@"viewControllers"];
_centerPanel = centerPanel;
+ [_centerPanel addObserver:self forKeyPath:@"viewControllers" options:0 context:nil];
}
if (self.isViewLoaded && self.state == JASidePanelCenterVisible) {
[self _swapCenter:previous with:_centerPanel];
@@ -281,6 +286,7 @@ - (void)setLeftPanel:(UIViewController *)leftPanel {
[_leftPanel removeFromParentViewController];
_leftPanel = leftPanel;
[self addChildViewController:_leftPanel];
+ [self _placeButtonForLeftPanel];
}
}
@@ -294,6 +300,23 @@ - (void)setRightPanel:(UIViewController *)rightPanel {
}
}
+#pragma mark - Panel Buttons
+
+- (void)_placeButtonForLeftPanel {
+ if (self.leftPanel) {
+ UIViewController *buttonController = self.gestureController;
+ if ([buttonController isKindOfClass:[UINavigationController class]]) {
+ UINavigationController *nav = (UINavigationController *)buttonController;
+ if ([nav.viewControllers count] > 0) {
+ buttonController = [nav.viewControllers objectAtIndex:0];
+ }
+ }
+ if (!buttonController.navigationItem.leftBarButtonItem) {
+ buttonController.navigationItem.leftBarButtonItem = [self leftButtonForCenterPanel];
+ }
+ }
+}
+
#pragma mark - Gesture Recognizer Delegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
@@ -442,14 +465,12 @@ - (void)_loadCenterPanel {
[self _addPanGestureToView:self.gestureController.view];
}
[self.gestureController addObserver:self forKeyPath:@"view" options:0 context:nil];
+
+ [self _placeButtonForLeftPanel];
_centerPanel.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_centerPanel.view.frame = self.centerPanelContainer.bounds;
[self stylePanel:_centerPanel.view];
-
- if (self.leftPanel && !self.gestureController.navigationItem.leftBarButtonItem) {
- self.gestureController.navigationItem.leftBarButtonItem = [self leftButtonForCenterPanel];
- }
}
- (void)_loadLeftPanel {
@@ -623,6 +644,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
if (self.gestureController.isViewLoaded) {
[self _addPanGestureToView:self.gestureController.view];
}
+ } else if ([keyPath isEqualToString:@"viewControllers"] && object == self.centerPanel) {
+ // view controllers have changed, need to replace the button
+ [self _placeButtonForLeftPanel];
}
}
@@ -633,14 +657,7 @@ - (UIBarButtonItem *)leftButtonForCenterPanel {
}
- (UIViewController *)gestureController {
- UIViewController *result = self.centerPanel;
- if ([result isKindOfClass:[UINavigationController class]]) {
- UINavigationController *nav = (UINavigationController *)result;
- if ([nav.viewControllers count] > 0) {
- result = [nav.viewControllers objectAtIndex:0];
- }
- }
- return result;
+ return self.centerPanel;
}
- (void)showLeftPanel:(BOOL)animated {

0 comments on commit 070a89f

Please sign in to comment.