判断左右触摸滑动

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

{

    UITouch *touch = [touches anyObject];

CGPoint location = [touch locationInView:self];

lastLoction = location;

moveChanged = NO;

}


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

{

     UITouch *touch = [touches anyObject];

     CGPoint location = [touch locationInView:self];

    if(!moveChanged && fabs(location.x - lastLoction.x) > 60 && fabs(location.y - lastLoction.y) < 25){

moveChanged = YES;

        if(location.x - lastLoction.x >0){//right

            NSLog(@"this right");

            [self switchViews:nil];

        }else{//left

            NSLog(@"this left");

[self switchViews:nil];

}

    }


}


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

{

    CGPoint location = [[touches anyObject] locationInView:self];

    lastLoction = location;


}

你可能感兴趣的:(判断左右触摸滑动)