备忘

# pragma mark - Gestures
- (void)slideDraw:(UIPanGestureRecognizer *)recognizer {
    CGRect frame = self.viewController.drawContaintView.frame;
    CGFloat x = CGRectGetMinX(frame);
    CGPoint translatedPoint = [recognizer translationInView:self.viewController.drawContaintView];
    x += translatedPoint.x;
    if (x > 0) {
        x = 0;
    }
    frame.origin.x = x;
    self.viewController.drawContaintView.frame = frame;
    
    if (recognizer.state == UIGestureRecognizerStateEnded){
        CGRect currentFrame = self.viewController.drawContaintView.frame;
        if (currentFrame.origin.x < -(SCREEN_WIDTH/4.0)){
            [self hideDraw];
        }else {
            [self showDraw];
        }
    }

    [recognizer setTranslation:CGPointMake(0, 0) inView:self.viewController.drawContaintView];
}
//手势识别
- (void)slideShowDraw:(UIPanGestureRecognizer *)recognizer {

    CGPoint transPoint = [recognizer translationInView:self.view];
    self.cgx += transPoint.x;
    CGFloat benganX;
    if (transPoint.x > benganX) {
    }else {
        [self.viewController.drawContaintView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3 - self.cgx/SCREEN_WIDTH* 0.3]];
    }
    if (recognizer.state == UIGestureRecognizerStateBegan ) {
        CGPoint location = [recognizer locationInView:self.view];
        benganX = location.x;
    }
    NSLog(@"%f%f", transPoint.x, transPoint.y);
    if (benganX < 50 && recognizer.state == UIGestureRecognizerStateChanged) {
        CGRect frame = self.viewController.drawContaintView.frame;
        CGFloat x = CGRectGetMinX(frame);
        x += transPoint.x+0.3;
        frame.origin.x = x;
        self.viewController.drawContaintView.frame = frame;
    }
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        CGRect currentFrame = self.viewController.drawContaintView.frame;
        if (currentFrame.origin.x < -(SCREEN_WIDTH/4.0*3)){
            [self hideDraw];
        }else {
            [self showDraw];
        }
    }
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.viewController.drawContaintView];
}

//弹出边栏
- (void)leftBarButtonTouched {

    [self.weakPkController showViewController:self.weakPkController.leftViewController];
    //[revealController setMinimumWidth:220.0 maximumWidth:244.0 forViewController:self];
   // revealController.delegate = self;
//    [self presentViewController:revealController animated:YES completion:nil];

//    DLog(@"Button Touched");
//    if (!self.viewController.isShowLeftView){
//        [UIView animateWithDuration:0.3 animations:^{
//            [self.viewController.drawContaintView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]];
//            [self showDraw];
//        }];
//    }else {
//            [UIView animateWithDuration:0.3 animations:^{
//                [self hideDraw];
//            }];
//    }
}

//点击隐藏边栏
- (void)hideDraw:(UITapGestureRecognizer *)recognizer {
    CGPoint location = [recognizer locationInView:self.viewController.drawContaintView];
    if (location.x > SCREEN_WIDTH/4.0*3.0) {
        [UIView animateWithDuration:0.3 animations:^{
            [self hideDraw];
        }];
    }
}

//显示边栏
- (void)showDraw {
    CGFloat width = SCREEN_WIDTH;
    CGFloat height = SCREEN_HEIGHT-(HEADHEIGHT+TabBar_HEIGHT);
//    UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
//    UIGraphicsBeginImageContext(screenWindow.frame.size);
//    [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()];
//    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = CGRectMake(0, 0, width, height);
        self.viewController.drawContaintView.frame = frame;
        self.viewController.isShowLeftView = YES;
        [UIView animateWithDuration:0.3 animations:^{
            [self.viewController.drawContaintView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]];
        }];
//        self.viewController.drawContaintView.layer.contents = (id)viewImage.CGImage;
    }];
}

//隐藏边栏
- (void)hideDraw {
    CGFloat width = SCREEN_WIDTH;
    CGFloat height = SCREEN_HEIGHT-(HEADHEIGHT+TabBar_HEIGHT);
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = CGRectMake(-width, 0, width, height);
        self.viewController.drawContaintView.frame = frame;
        self.viewController.isShowLeftView = NO;
    }];
}

# pragma mark - UIGestureRcognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint point = [gestureRecognizer locationInView:self.viewController.drawContaintView];
    
    if (point.x <= SCREEN_WIDTH/4.0*3.0) {
        return NO;
    }else{
        return YES;
    }
}
原文地址:https://www.cnblogs.com/code-changeworld/p/4752017.html