Skip to content

Commit

Permalink
Add options to enable/disable swipe gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
hossamghareeb committed Aug 14, 2015
1 parent 6ae9db7 commit ed3f03a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
Binary file not shown.
3 changes: 3 additions & 0 deletions Demo/Timeline/Timeline/AppDelegate.swift
Expand Up @@ -26,6 +26,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
rootVC.leftViewController = leftVC;
rootVC.centerEndScale = 0.4;

rootVC.enableLeftSwipeGesture = false
rootVC.enableRightSwipeGesture = false

return true
}

Expand Down
9 changes: 9 additions & 0 deletions SwiftySideMenu/SwiftySideMenuViewController.h
Expand Up @@ -41,6 +41,15 @@ typedef enum {
*/
@property (nonatomic, assign) float centerEndScale;

/*!
* @brief enable or disable the left swipe gesture. The left swipe gesture will toggle the side menu if the left side is opened. Default value is YES
*/
@property (nonatomic, assign) BOOL enableLeftSwipeGesture;

/*!
* @brief enable or disable the right swipe gesture. The right swipe gesture will toggle the side menu if the left side is NOT opened. Default value is YES
*/
@property (nonatomic, assign) BOOL enableRightSwipeGesture;

/*!
* @discussion toggle the left side menu. If its opened it will be closed and vice versa.
Expand Down
67 changes: 55 additions & 12 deletions SwiftySideMenu/SwiftySideMenuViewController.m
Expand Up @@ -24,6 +24,9 @@ @interface SwiftySideMenuViewController ()<POPAnimationDelegate, UIGestureRecogn
@property (nonatomic) CGFloat centerPopAnimationProgress;
@property (nonatomic) CGFloat leftPopAnimationProgress;

@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGesture;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGesture;

@end

@implementation SwiftySideMenuViewController
Expand All @@ -40,10 +43,59 @@ -(instancetype)init{
//The default value of scaling center view.
self.centerEndScale = 0.6;

self.enableLeftSwipeGesture = YES;
self.enableRightSwipeGesture = YES;
}
return self;
}


#pragma mark - Swipe Gestures -

-(void)setEnableLeftSwipeGesture:(BOOL)enableLeftSwipeGesture{
if (enableLeftSwipeGesture) {
[self addLeftSwipeGesture];
}
else{
if (self.leftSwipeGesture) {
[self.view removeGestureRecognizer:self.leftSwipeGesture];
}

}

_enableLeftSwipeGesture = enableLeftSwipeGesture;
}
-(void)setEnableRightSwipeGesture:(BOOL)enableRightSwipeGesture{
if (enableRightSwipeGesture) {
[self addRightSwipeGesture];
}
else{
if (self.rightSwipeGesture) {
[self.view removeGestureRecognizer:self.rightSwipeGesture];
}
}

_enableRightSwipeGesture = enableRightSwipeGesture;
}

-(void)addLeftSwipeGesture{
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGesture.delegate = self;
[self.view addGestureRecognizer:swipeGesture];
self.leftSwipeGesture = swipeGesture;
}

-(void)addRightSwipeGesture{


UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
swipeGesture.delegate = self;
[self.view addGestureRecognizer:swipeGesture];
self.rightSwipeGesture = swipeGesture;
}

-(void)didSwipeLeft:(UISwipeGestureRecognizer *)gesture{
if ([self isLeftMenuOpened]) {
[self toggleSideMenu];
Expand All @@ -56,6 +108,8 @@ -(void)didSwipeRight:(UISwipeGestureRecognizer *)gesture{
}
}

#pragma mark - Left & Center Views -

-(void)setLeftViewController:(UIViewController *)leftVC{

if ([leftVC isEqual:self.leftViewController]) {
Expand All @@ -69,17 +123,6 @@ -(void)setLeftViewController:(UIViewController *)leftVC{

_leftViewController = leftVC;

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGesture.delegate = self;
[self.view addGestureRecognizer:swipeGesture];

UISwipeGestureRecognizer *swipeGesture2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)];
swipeGesture2.direction = UISwipeGestureRecognizerDirectionRight;
swipeGesture2.delegate = self;
[self.view addGestureRecognizer:swipeGesture2];


_leftViewController.swiftySideMenu = self;
[self.view insertSubview:_leftViewController.view belowSubview:self.centerViewController.view];

Expand Down Expand Up @@ -228,7 +271,7 @@ - (void)pop_animationDidStop:(POPAnimation *)anim finished:(BOOL)finished{

}

#pragma mark - Gestures -
#pragma mark - UIGestureDelegate -

// called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocked by the other
// return YES to allow both to recognize simultaneously. the default implementation returns NO (by default no two gestures can be recognized simultaneously)
Expand Down

0 comments on commit ed3f03a

Please sign in to comment.