Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two problems #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 41 additions & 53 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@
static NSString *MMDrawerCenterKey = @"MMDrawerCenter";
static NSString *MMDrawerOpenSideKey = @"MMDrawerOpenSide";

@interface UIView (navigationBar)

-(UINavigationBar*)navigationBarContainedWithinSubviewsOfView;

@end

@implementation UIView (navigationBar)

-(UINavigationBar*)navigationBarContainedWithinSubviewsOfView{
UINavigationBar * navBar = nil;
for(UIView * subview in [self subviews]){
if([self isKindOfClass:[UINavigationBar class]]){
navBar = (UINavigationBar*)self;
break;
}
else {
navBar = [subview navigationBarContainedWithinSubviewsOfView];
if (navBar != nil) {
break;
}
}
}
return navBar;
}

@end

@interface MMDrawerCenterContainerView : UIView
@property (nonatomic,assign) MMDrawerOpenCenterInteractionMode centerInteractionMode;
@property (nonatomic,assign) MMDrawerSide openSide;
Expand All @@ -91,7 +118,7 @@ -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView = [super hitTest:point withEvent:event];
if(hitView &&
self.openSide != MMDrawerSideNone){
UINavigationBar * navBar = [self navigationBarContainedWithinSubviewsOfView:self];
UINavigationBar * navBar = [self navigationBarContainedWithinSubviewsOfView];
CGRect navBarFrame = [navBar convertRect:navBar.bounds toView:self];
if((self.centerInteractionMode == MMDrawerOpenCenterInteractionModeNavigationBarOnly &&
CGRectContainsPoint(navBarFrame, point) == NO) ||
Expand All @@ -102,22 +129,6 @@ -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
return hitView;
}

-(UINavigationBar*)navigationBarContainedWithinSubviewsOfView:(UIView*)view{
UINavigationBar * navBar = nil;
for(UIView * subview in [view subviews]){
if([view isKindOfClass:[UINavigationBar class]]){
navBar = (UINavigationBar*)view;
break;
}
else {
navBar = [self navigationBarContainedWithinSubviewsOfView:subview];
if (navBar != nil) {
break;
}
}
}
return navBar;
}
@end

@interface MMDrawerController () <UIGestureRecognizerDelegate>{
Expand Down Expand Up @@ -395,24 +406,13 @@ -(void)setCenterViewController:(UIViewController *)centerViewController animated
}

if (_centerContainerView == nil) {
//This is related to Issue #152 (https://github.com/mutualmobile/MMDrawerController/issues/152)
// also fixed below in the getter for `childControllerContainerView`. Turns out we have
// two center container views getting added to the view during init,
// because the first request self.centerContainerView.bounds was kicking off a
// viewDidLoad, which caused us to be able to fall through this check twice.
//
//The fix is to grab the bounds, and then check again that the child container view has
//not been created.

CGRect centerFrame = self.childControllerContainerView.bounds;
if(_centerContainerView == nil){
_centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:centerFrame];
[self.centerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.centerContainerView setBackgroundColor:[UIColor clearColor]];
[self.centerContainerView setOpenSide:self.openSide];
[self.centerContainerView setCenterInteractionMode:self.centerHiddenInteractionMode];
[self.childControllerContainerView addSubview:self.centerContainerView];
}
_centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:centerFrame];
[self.centerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.centerContainerView setBackgroundColor:[UIColor clearColor]];
[self.centerContainerView setOpenSide:self.openSide];
[self.centerContainerView setCenterInteractionMode:self.centerHiddenInteractionMode];
[self.childControllerContainerView addSubview:self.centerContainerView];
}

UIViewController * oldCenterViewController = self.centerViewController;
Expand Down Expand Up @@ -1001,21 +1001,11 @@ -(CGFloat)visibleRightDrawerWidth{

-(UIView*)childControllerContainerView{
if(_childControllerContainerView == nil){
//Issue #152 (https://github.com/mutualmobile/MMDrawerController/issues/152)
//Turns out we have two child container views getting added to the view during init,
//because the first request self.view.bounds was kicking off a viewDidLoad, which
//caused us to be able to fall through this check twice.
//
//The fix is to grab the bounds, and then check again that the child container view has
//not been created.
CGRect childContainerViewFrame = self.view.bounds;
if(_childControllerContainerView == nil){
_childControllerContainerView = [[UIView alloc] initWithFrame:childContainerViewFrame];
[_childControllerContainerView setBackgroundColor:[UIColor clearColor]];
[_childControllerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_childControllerContainerView];
}

_childControllerContainerView = [[UIView alloc] initWithFrame:childContainerViewFrame];
[_childControllerContainerView setBackgroundColor:[UIColor clearColor]];
[_childControllerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[self.view addSubview:_childControllerContainerView];
}
return _childControllerContainerView;
}
Expand Down Expand Up @@ -1445,11 +1435,9 @@ -(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestur

-(BOOL)isPointContainedWithinNavigationRect:(CGPoint)point{
CGRect navigationBarRect = CGRectNull;
if([self.centerViewController isKindOfClass:[UINavigationController class]]){
UINavigationBar * navBar = [(UINavigationController*)self.centerViewController navigationBar];
navigationBarRect = [navBar convertRect:navBar.bounds toView:self.childControllerContainerView];
navigationBarRect = CGRectIntersection(navigationBarRect,self.childControllerContainerView.bounds);
}
UINavigationBar * navBar = [self.centerViewController.view navigationBarContainedWithinSubviewsOfView];
navigationBarRect = [navBar convertRect:navBar.bounds toView:self.childControllerContainerView];
navigationBarRect = CGRectIntersection(navigationBarRect,self.childControllerContainerView.bounds);
return CGRectContainsPoint(navigationBarRect,point);
}

Expand Down