UITableView 手势

3.2以前

#pragma mark - touch methods

@interface BaseUITableViewCell : UITableViewCell

{

    CGPoint touchBeganPoint;

    BaseUIViewController *_baseUIVC;

}

}


@property (nonatomic, retain) BaseUIViewController *_baseUIVC;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier baseUIVC:(BaseUIViewController*)baseUIVC;

@end


@implementation BaseUITableViewCell

@synthesize _baseUIVC;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier baseUIVC:(BaseUIViewController*)baseUIVC

{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        // Initialization code

        _baseUIVC = baseUIVC;

    }

    return self;

}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];

    touchBeganPoint = [touch locationInView:[[UIApplication sharedApplication] keyWindow]];

    [[self nextResponder] touchesBegan:touches withEvent:event];

    [super touchesBegan:touches withEvent:event];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    [[self nextResponder] touchesMoved:touches withEvent:event];

    [super touchesMoved:touches withEvent:event];

    

    UITouch *touch = [touches anyObject];

    CGPoint touchPoint = [touch locationInView:[[UIApplication sharedApplication] keyWindow]];

    

    CGFloat xOffSet = touchPoint.x - touchBeganPoint.x;

    if (xOffSet < 0) {

//        [APP_DELEGATE makeRightViewVisible];

//        [vc moveToLeftSide];

    }

    else if (xOffSet > 0) {

        [APP_DELEGATE makeLeftViewVisible];

        [_baseUIVC moveToRightSide];

    }

    

}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {


    [[self nextResponder] touchesEnded:touches withEvent:event];

    [super touchesEnded:touches withEvent:event];

    

}

@end


3.2以后

#pragma mark - UIGestureRecognizer method

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    touchBeganPoint = [gestureRecognizer locationInView:self.view];

    return YES;

}


- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {        

    //拿到手指目前的位置

    CGPoint touchPoint = [recognizer locationInView:self.view];

    

    CGFloat xOffSet = touchPoint.x - touchBeganPoint.x;

    if (xOffSet < 0) {

        //        [APP_DELEGATE makeRightViewVisible];

        //        [vc moveToLeftSide];

    }

    else if (xOffSet > 0) {

        [APP_DELEGATE makeLeftViewVisible];

        [self moveToRightSide];

    }

}



你可能感兴趣的:(ios)