UITableView 手势

来源:互联网 发布:梦想的故事 知乎 编辑:程序博客网 时间:2024/05/01 12:04

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 = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        // Initialization code

        _baseUIVC = baseUIVC;

    }

    returnself;

}


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

    UITouch *touch = [touchesanyObject];

    touchBeganPoint = [touchlocationInView:[[UIApplicationsharedApplication] keyWindow]];

    [[selfnextResponder] touchesBegan:touches withEvent:event];

    [supertouchesBegan:touches withEvent:event];

}


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

    [[selfnextResponder] touchesMoved:touches withEvent:event];

    [supertouchesMoved:touches withEvent:event];

    

    UITouch *touch = [touchesanyObject];

    CGPoint touchPoint = [touchlocationInView:[[UIApplicationsharedApplication] keyWindow]];

    

    CGFloat xOffSet = touchPoint.x -touchBeganPoint.x;

    if (xOffSet <0) {

//        [APP_DELEGATE makeRightViewVisible];

//        [vc moveToLeftSide];

    }

    elseif (xOffSet > 0) {

        [APP_DELEGATEmakeLeftViewVisible];

        [_baseUIVCmoveToRightSide];

    }

    

}


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


    [[selfnextResponder] touchesEnded:touches withEvent:event];

    [supertouchesEnded:touches withEvent:event];

    

}

@end


3.2以后

#pragma mark - UIGestureRecognizer method

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

    touchBeganPoint = [gestureRecognizerlocationInView:self.view];

    returnYES;

}


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

    //拿到手指目前的位置

    CGPoint touchPoint = [recognizerlocationInView:self.view];

    

    CGFloat xOffSet = touchPoint.x -touchBeganPoint.x;

    if (xOffSet <0) {

        //        [APP_DELEGATE makeRightViewVisible];

        //        [vc moveToLeftSide];

    }

    elseif (xOffSet > 0) {

        [APP_DELEGATEmakeLeftViewVisible];

        [selfmoveToRightSide];

    }

}



原创粉丝点击