Skip to content

Commit 3921c60

Browse files
committed
Hanlde pan gesture conflicts
1 parent 418a1cb commit 3921c60

36 files changed

Lines changed: 606 additions & 313 deletions

LMSideBarController.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "LMSideBarController"
4-
s.version = "1.0.1"
4+
s.version = "1.0.2"
55
s.summary = "LMSideBarController is a simple side bar controller inspired by Tappy"
66
s.homepage = "https://github.com/lminhtm/LMSideBarController"
77
s.license = 'MIT'

LMSideBarController/LMSideBarController.m

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ - (void)setMenuViewController:(UIViewController *)menuViewController forDirectio
155155
// Add the new one
156156
[self.menuViewControllers setObject:menuViewController forKey:@(direction)];
157157
if (direction == LMSideBarControllerDirectionLeft) {
158-
[self setupViewController:menuViewController frame:CGRectMake(-self.view.bounds.size.width,
158+
[self setupViewController:menuViewController frame:CGRectMake(-menuViewController.view.bounds.size.width,
159159
0,
160-
self.view.bounds.size.width,
160+
menuViewController.view.bounds.size.width,
161161
self.view.bounds.size.height)];
162162
}
163163
else {
164164
[self setupViewController:menuViewController frame:CGRectMake(self.view.bounds.size.width,
165165
0,
166-
self.view.bounds.size.width,
166+
menuViewController.view.bounds.size.width,
167167
self.view.bounds.size.height)];
168168
}
169169
menuViewController.view.hidden = YES;
@@ -323,6 +323,12 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
323323
{
324324
if ([gestureRecognizer isEqual:self.panGestureRecognizer])
325325
{
326+
LMSideBarStyle *style = [self styleForDirection:_currentDirection];
327+
BOOL shouldHandle = [style panGestureRecognizerShouldBegin:gestureRecognizer];
328+
if (!shouldHandle) {
329+
return NO;
330+
}
331+
326332
CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:gestureRecognizer.view];
327333
BOOL horizontalPan = fabs(velocity.x) > fabs(velocity.y);
328334

@@ -425,40 +431,30 @@ - (BOOL)shouldAutorotate
425431
return NO;
426432
}
427433

428-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
434+
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
429435
{
430-
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
436+
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
431437

432438
// Update menu view frame
433439
UIViewController *leftMenuViewController = [self menuViewControllerForDirection:LMSideBarControllerDirectionLeft];
434440
if (leftMenuViewController) {
435-
leftMenuViewController.view.frame = CGRectMake(-self.view.bounds.size.width,
441+
leftMenuViewController.view.frame = CGRectMake(-leftMenuViewController.view.bounds.size.width,
436442
0,
437-
self.view.bounds.size.width,
443+
leftMenuViewController.view.bounds.size.width,
438444
self.view.bounds.size.height);
439445
}
440446

441447
UIViewController *rightMenuViewController = [self menuViewControllerForDirection:LMSideBarControllerDirectionRight];
442448
if (rightMenuViewController) {
443449
rightMenuViewController.view.frame = CGRectMake(self.view.bounds.size.width,
444450
0,
445-
self.view.bounds.size.width,
451+
rightMenuViewController.view.bounds.size.width,
446452
self.view.bounds.size.height);
447453
}
448454

449455
// Let current side bar style to handle rotation
450456
if (_currentStyle) {
451-
[_currentStyle willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
452-
}
453-
}
454-
455-
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
456-
{
457-
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
458-
459-
// Let current side bar style to handle rotation
460-
if (_currentStyle) {
461-
[_currentStyle didRotateFromInterfaceOrientation:fromInterfaceOrientation];
457+
[_currentStyle viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
462458
}
463459
}
464460

LMSideBarController/LMSideBarStyles/LMSideBarDepthStyle.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ - (void)hideMenuViewController:(BOOL)animated
210210
[self finishHiding:animated];
211211
}
212212

213+
- (BOOL)panGestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
214+
{
215+
CGPoint point = [gestureRecognizer locationInView:gestureRecognizer.view];
216+
if (point.x < gestureRecognizer.view.bounds.size.width - self.menuWidth
217+
&& self.sideBarController.currentDirection == LMSideBarControllerDirectionRight) {
218+
return YES;
219+
}
220+
if (point.x > self.menuWidth
221+
&& self.sideBarController.currentDirection == LMSideBarControllerDirectionLeft) {
222+
return YES;
223+
}
224+
return NO;
225+
}
226+
213227
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer
214228
{
215229
CGPoint touchLocation = [tapGestureRecognizer locationInView:tapGestureRecognizer.view];
@@ -313,7 +327,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
313327
}
314328
}
315329

316-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
330+
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
317331
{
318332
LMSideBarControllerDirection direction = self.sideBarController.currentDirection;
319333
LMSideBarControllerState state = self.sideBarController.currentState;

LMSideBarController/LMSideBarStyles/LMSideBarStyle.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
*/
6666
- (void)hideMenuViewController:(BOOL)animated;
6767

68+
/**
69+
Handle pan gesture
70+
*/
71+
- (BOOL)panGestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
72+
6873
/**
6974
Handle tap gesture
7075
@@ -82,11 +87,6 @@
8287
/**
8388
Handle rotation
8489
*/
85-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
86-
87-
/**
88-
Handle rotation
89-
*/
90-
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
90+
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;
9191

9292
@end

LMSideBarController/LMSideBarStyles/LMSideBarStyle.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ - (void)hideMenuViewController:(BOOL)animated
2525
// For subclass
2626
}
2727

28-
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer
28+
- (BOOL)panGestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
2929
{
30-
// For subclass
30+
return YES;
3131
}
3232

33-
- (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
33+
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer
3434
{
3535
// For subclass
3636
}
3737

38-
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
38+
- (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer
3939
{
4040
// For subclass
4141
}
4242

43-
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
43+
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
4444
{
4545
// For subclass
4646
}

0 commit comments

Comments
 (0)