Skip to content

Commit

Permalink
Refactored bezel gesture detection based on #56
Browse files Browse the repository at this point in the history
  • Loading branch information
kcharwood committed Jul 10, 2013
1 parent 8417a47 commit 1344863
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions MMDrawerController/MMDrawerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1011,17 +1011,18 @@ -(UIViewController*)sideDrawerViewControllerForSide:(MMDrawerSide)drawerSide{
#pragma mark - UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
CGPoint point = [touch locationInView:self.view];

BOOL shouldReceiveTouch = NO;
if(self.openSide == MMDrawerSideNone){
MMOpenDrawerGestureMode possibleOpenGestureModes = [self possibleOpenGestureModesForGestureRecognizer:gestureRecognizer
withTouchPoint:point];
return ((self.openDrawerGestureModeMask & possibleOpenGestureModes)>0);
shouldReceiveTouch = ((self.openDrawerGestureModeMask & possibleOpenGestureModes)>0);
}
else{
MMCloseDrawerGestureMode possibleCloseGestureModes = [self possibleCloseGestureModesForGestureRecognizer:gestureRecognizer
withTouchPoint:point];
return ((self.closeDrawerGestureModeMask & possibleCloseGestureModes)>0);
shouldReceiveTouch = ((self.closeDrawerGestureModeMask & possibleCloseGestureModes)>0);
}
return shouldReceiveTouch;
}

#pragma mark Gesture Recogizner Delegate Helpers
Expand All @@ -1042,7 +1043,12 @@ -(MMCloseDrawerGestureMode)possibleCloseGestureModesForGestureRecognizer:(UIGest
if([self isPointContainedWithinCenterViewContentRect:point]){
possibleCloseGestureModes |= MMCloseDrawerGestureModePanningCenterView;
}
if([self isPointContainedWithinBezelRect:point]){
if([self isPointContainedWithRightBezelRect:point] &&
self.openSide == MMDrawerSideLeft){
possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
}
if([self isPointContainedWithinLeftBezelRect:point] &&
self.openSide == MMDrawerSideRight){
possibleCloseGestureModes |= MMCloseDrawerGestureModeBezelPanningCenterView;
}
if([self isPointContainedWithinCenterViewContentRect:point] == NO &&
Expand All @@ -1062,9 +1068,15 @@ -(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestur
if([self isPointContainedWithinCenterViewContentRect:point]){
possibleOpenGestureModes |= MMOpenDrawerGestureModePanningCenterView;
}
if([self isPointContainedWithinBezelRect:point]){
if([self isPointContainedWithinLeftBezelRect:point] &&
self.leftDrawerViewController){
possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
}
if([self isPointContainedWithRightBezelRect:point] &&
self.rightDrawerViewController){
possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
}

}
return possibleOpenGestureModes;
}
Expand All @@ -1087,17 +1099,20 @@ -(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
[self isPointContainedWithinNavigationRect:point] == NO);
}

-(BOOL)isPointContainedWithinBezelRect:(CGPoint)point{
CGRect leftBezelRect;
-(BOOL)isPointContainedWithinLeftBezelRect:(CGPoint)point{
CGRect leftBezelRect = CGRectNull;
CGRect tempRect;
CGRectDivide(self.view.bounds, &leftBezelRect, &tempRect, MMDrawerBezelRange, CGRectMinXEdge);

CGRect rightBezelRect;
return (CGRectContainsPoint(leftBezelRect, point) &&
[self isPointContainedWithinCenterViewContentRect:point]);
}

-(BOOL)isPointContainedWithRightBezelRect:(CGPoint)point{
CGRect rightBezelRect = CGRectNull;
CGRect tempRect;
CGRectDivide(self.view.bounds, &rightBezelRect, &tempRect, MMDrawerBezelRange, CGRectMaxXEdge);

return ((CGRectContainsPoint(leftBezelRect, point) ||
CGRectContainsPoint(rightBezelRect, point)) &&
[self isPointContainedWithinCenterViewContentRect:point]);
return (CGRectContainsPoint(rightBezelRect, point) &&
[self isPointContainedWithinCenterViewContentRect:point]);
}

@end

0 comments on commit 1344863

Please sign in to comment.