A lightweight, easy to use, Side Drawer Navigation Controller
Clone or download
Pull request Compare This branch is 7 commits ahead of mutualmobile:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
KitchenSink
MMDrawerController
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
MMDrawerController.podspec
README.md

README.md

修改

MMDrawerController.m

添加变量

typedef NS_ENUM(NSInteger,MMDrawerAllowOpenSide){
    MMDrawerAllowOpenSideAll = 0,
    MMDrawerAllowOpenSideLeftOnly,
    MMDrawerAllowOpenSideRightOnly,
    MMDrawerAllowOpenSideNone,
};

/**
 All user to open which side of drawer by gesture
 
 Default MMDrawerAllowOpenSideAll
 */
@property (nonatomic, assign) MMDrawerAllowOpenSide drawerAllowOpenSide;

1377 行添加下面的方法:

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
        UIPanGestureRecognizer *pan = (UIPanGestureRecognizer*)gestureRecognizer;
        CGPoint p= [pan translationInView:self.view];
        
        if(self.drawerAllowOpenSide == MMDrawerAllowOpenSideNone){
            return NO;
        }else if(self.drawerAllowOpenSide == MMDrawerAllowOpenSideAll){
            return YES;
        }else if(self.drawerAllowOpenSide == MMDrawerAllowOpenSideRightOnly && p.x>=0 && self.openSide==MMDrawerSideNone){
            //禁止用户滑动打开左侧抽屉
            return NO;
        }else if(self.drawerAllowOpenSide == MMDrawerAllowOpenSideLeftOnly && p.x<=0 && self.openSide==MMDrawerSideRight){
            //禁止用户滑动打开左侧抽屉
            return NO;
        }
    }
    return YES;
}

1158 行修改:

#pragma mark - Animation helpers
-(void)finishAnimationForPanGestureWithXVelocity:(CGFloat)xVelocity completion:(void(^)(BOOL finished))completion{
    CGFloat currentOriginX = CGRectGetMinX(self.centerContainerView.frame);
    
    CGFloat animationVelocity = MAX(ABS(xVelocity),self.panVelocityXAnimationThreshold*2);
    
    if(self.openSide == MMDrawerSideLeft) {
        CGFloat midPoint = self.maximumLeftDrawerWidth / 2.0;
        if(xVelocity > self.panVelocityXAnimationThreshold){
            //不让用户从右侧抽屉直接滑动到左侧抽屉
//            [self openDrawerSide:MMDrawerSideLeft animated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
        }
        else if(xVelocity < -self.panVelocityXAnimationThreshold){
            [self closeDrawerAnimated:YES velocity:animationVelocity animationOptions:UIViewAnimationOptionCurveEaseOut completion:completion];
        }
        else if(currentOriginX < midPoint){
            [self closeDrawerAnimated:YES completion:completion];
        }
        else {
            [self openDrawerSide:MMDrawerSideLeft animated:YES completion:completion];
        }
    }